|
-
May 8th, 2013, 11:39 AM
#1
Thread Starter
Member
[RESOLVED] Time Stamp / Storage of Time in DB
Hello all
I Am storing time in a SQL db and right now the time is stored in HH.MM.SS
I would like to only store the HH.MM.
I know how to use the following to string
DateTime.Now.ToString("MM/dd/yyyy hh:mm tt")
but I am not storing in in String I storing in in a time field.
I guess All i need to do is change the seconds to 00.
ie 17:39:47 changed to 17:39:00
Thanks
-
May 8th, 2013, 11:44 AM
#2
Re: Time Stamp / Storage of Time in DB
In the MSDN documentation for DateTime, you'll notice that one of the constructors (a way to create an object) takes the Year, Month, Day, Hour, Minute, and Second for the DateTime structure. Knowing this, you could easily, say, use the DateTime.Now property and create a new DateTime object with all the parameters set, except for second, which you would just pass 0 in.
-
May 8th, 2013, 11:52 AM
#3
Re: Time Stamp / Storage of Time in DB
Are you storing the date as a string? Why not as a Date?
-
May 8th, 2013, 11:53 AM
#4
Re: Time Stamp / Storage of Time in DB
 Originally Posted by dbasnett
Are you storing the date as a string? Why not as a Date?
Silly dbasnett!
but I am not storing in in String I storing in in a time field.
-
May 8th, 2013, 11:59 AM
#5
Re: Time Stamp / Storage of Time in DB
 Originally Posted by formlesstree4
Silly dbasnett!
Ooops!
-
May 8th, 2013, 12:23 PM
#6
Thread Starter
Member
Re: Time Stamp / Storage of Time in DB
LOL with/ dbasnett
OK
I (being and vbdummy) am a bit confused at the MSDN info.
My Punchtime comes in the form of a label displaying the time for the user.
Code:
Public Sub Timer1_tick(ByVal sender As Object, ByVal e As EventArgs)
'on screen clock
Label1.Text = Now.ToLongTimeString
End Sub
I then use the time from the label like this
Code:
Dim ShortPunchTime As TimeSpan = New TimeSpan(0, 0, 0, 0)
Dim PunchTime As DateTime = DateTime.Parse(Label1.Text)
ShortPunchTime = PunchTime.TimeOfDay
I am then storing SHortPunchTime into A DB with a StoredProcedure into a time() field.
???
-
May 8th, 2013, 12:25 PM
#7
Thread Starter
Member
Re: Time Stamp / Storage of Time in DB
OK now its my turn to BEAT myself in the head for being "silly"
now.toshorttimestring
DUH
-
May 8th, 2013, 01:53 PM
#8
Re: Time Stamp / Storage of Time in DB
That will work, but I really dislike the idea of taking a perfectly good date, turning it into a string, then turning that string back into a date. How about just having a date variable at form scope. Store the current time in the variable and just use the label to display the contents of the variable. Technically, it will matter very little, in this case, as there is only one less conversion by storing the date in a date variable, but I'd say that it's a good habit to avoid as many conversions from strings as you can.
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|