ASP.NET conversion

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cherychoclatecandy
    New Member
    • May 2008
    • 10

    ASP.NET conversion

    I would like to know how do i convert a datetime to time format only?

    for eg
    datetime:5/5/2008 8:35:09 AM to time: 8:35:09 only.
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    Code:
    DateTime dt = DateTime.Parse("5/5/2008 8:35:09 AM");
    l1.Text = dt.ToString("hh:mm:ss");
    Change l1.Text to whatever string you want.

    Check out this link for more ways to use a format string.

    Comment

    • cherychoclatecandy
      New Member
      • May 2008
      • 10

      #3
      I am quite unsure where to declare the conversion.I got this from some other website and edited to suit my needs.


      Dim minutes, totminutes, hours As Double
      Dim total5a, total5, total2, spare, fromtime, totime As DateTime
      Dim lunch, lunchstart, lunchend As String

      Dim connAdd As New SqlConnection _
      ("data source = 15-11\SQLEXPRESS; initial catalog=FASSQL; " & _
      "integrated security = true")

      connAdd.Open()

      Dim count As New SqlCommand("Sel ect COUNT(UID)As Count from TALog", connAdd)
      Dim dr1 As SqlDataReader
      dr1 = count.ExecuteRe ader()

      If dr1.Read() Then
      lblCount.Text = dr1("Count")
      End If


      fromtime = Date.FromOADate (CDate("08:30 am").ToOADate() )
      totime = Date.FromOADate (CDate("5:30 pm").ToOADate() )

      lunch = 0

      If DateDiff("n", "12:30 pm", fromtime) < 0 Then
      lunchstart = "12:30pm"
      Else
      lunchstart = fromtime.ToOADa te()
      End If

      If DateDiff("n", "13:30 pm", totime) > 0 Then
      lunchend = "13:30 pm"
      Else

      lunchend = totime.ToOADate ()

      End If
      'DateTime(fromt ime = DateTime.Parse( "5/5/2008 8:30:00 AM"))
      '.Text = fromtime.ToStri ng("hh:mm:ss")

      lunch = DateDiff("n", lunchstart, lunchend)

      If lunch < 0 Then lunch = 0

      minutes = DateDiff("n", fromtime, totime)

      hours = Int((minutes - lunch) / 60)
      spare = Date.FromOADate ((minutes - lunch) Mod 60)
      total5 = hours & "." & spare

      total5a = CDate(total5)
      totminutes = Minute(total5a)
      total2 = hours & "." & Right("0" & (totminutes), 2)
      Response.Write( total2)

      End Sub

      Comment

      Working...