[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
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.
Re: Time Stamp / Storage of Time in DB
Are you storing the date as a string? Why not as a Date?
Re: Time Stamp / Storage of Time in DB
Quote:
Originally Posted by
dbasnett
Are you storing the date as a string? Why not as a Date?
Silly dbasnett!
Quote:
but I am not storing in in String I storing in in a time field.
Re: Time Stamp / Storage of Time in DB
Quote:
Originally Posted by
formlesstree4
Silly dbasnett!
Ooops! :blush:
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.
???
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
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.