This is a SQL problem but here it goes...
Does anyone know how to extract the time from a datetime datatype?
Printable View
This is a SQL problem but here it goes...
Does anyone know how to extract the time from a datetime datatype?
What exactly do you mean?
as far as I know the datetime field store the date and time in a standard format
e.g. dd/mm/yyyy hh.mm.ss (just an example...I think!)
to get just the time try something along the lines of..
left( variablename, 11)
This will then move 11 chars in and display the rest, which in my example is hh.mm.ss.
You'll need to be sure of the format first and probably need to do some trial and error on it.
You can also use right( variablename, starting point) it that is any easier.
:) H.
If all you want to have is the time as hh.mm.ss format, just use the following:
And here you go, u don't have to extract and u got the time stored as MyTime! :rolleyes:Code:Dim MyTime As String
MyTime = Format(Time, "Long Time")
The date part is to the left of the decimal, and the time part is to the right.
You can use Int(dtmVariable) to strip out the time. Probably, you can use dtmVariable - Int(dtmVariable) to strip out the date.
Or, you can use the DatePart function.
There is actually a function in VB6:
TimeValue(<date>)
If you place your variable in here you'll get what you want:
Hope this helps.Code:MyTime = TimeValue(SQLDateTimeVar)