Login or Sign Up
Logging in...
Remember me
Log in
Or
Sign Up
Forgot password or user name?
Log in with
Search in titles only
Search in .NET only
Search
Advanced Search
Forums
Product Launch
Updates
Today's Posts
Member List
Calendar
Home
Forum
Topic
.NET
ASP.NET conversion
Collapse
X
Collapse
Posts
Latest Activity
Photos
Page
of
1
Filter
Time
All Time
Today
Last Week
Last Month
Show
All
Discussions only
Photos only
Videos only
Links only
Polls only
Events only
Filtered by:
Clear All
new posts
Previous
template
Next
cherychoclatecandy
New Member
Join Date:
May 2008
Posts:
10
#1
ASP.NET conversion
Jun 18 '08, 01:34 AM
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
Join Date:
Apr 2008
Posts:
3264
#2
Jun 18 '08, 02:52 AM
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
Post
Cancel
cherychoclatecandy
New Member
Join Date:
May 2008
Posts:
10
#3
Jun 18 '08, 03:33 AM
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
Post
Cancel
Previous
template
Next
Working...
Yes
No
OK
OK
Cancel
👍
👎
☕
Comment