How to extract Hour, Minute & Second
How to extract Hour, Minute & Second
am 21.01.2007 13:45:10 von Dale
A table has a field containing the date and time. Example 2006-2-20
08:11:44.123...field name is DateInitiated. I can extract the month, day and
year by using Day(DateInitiated), Month(DateInitiated), Year(DateInitiated).
How would the time be extracted for hours, minutes and seconds?
Thanks!
Re: How to extract Hour, Minute & Second
am 21.01.2007 13:49:15 von Paul Lautman
Dale wrote:
> A table has a field containing the date and time. Example 2006-2-20
> 08:11:44.123...field name is DateInitiated. I can extract the month,
> day and year by using Day(DateInitiated), Month(DateInitiated),
> Year(DateInitiated). How would the time be extracted for hours,
> minutes and seconds?
> Thanks!
Would you believe HOUR() MINUTE() SECOND, or is that too obvious!
Re: How to extract Hour, Minute & Second
am 21.01.2007 16:23:09 von Rik
Paul Lautman wrote:
> Dale wrote:
>> A table has a field containing the date and time. Example 2006-2-20
>> 08:11:44.123...field name is DateInitiated. I can extract the month,
>> day and year by using Day(DateInitiated), Month(DateInitiated),
>> Year(DateInitiated). How would the time be extracted for hours,
>> minutes and seconds?
>> Thanks!
>
> Would you believe HOUR() MINUTE() SECOND, or is that too obvious!
That would be the preferred way to handle it at the db side indeed.
If you're doing different things with the date it might be more efficient
to do a date_parse
at the PHP side of things.
--
Rik Wasmus
Re: How to extract Hour, Minute & Second
am 21.01.2007 17:25:46 von Dale
Well Paul, I did try that and here's the message that comes back...
Server: Msg 195, Level 15, State 10, Line 1
'Hour' is not a recognized function name.
"Paul Lautman" wrote in message
news:51h5q7F1ipb3iU1@mid.individual.net...
> Dale wrote:
>> A table has a field containing the date and time. Example 2006-2-20
>> 08:11:44.123...field name is DateInitiated. I can extract the month,
>> day and year by using Day(DateInitiated), Month(DateInitiated),
>> Year(DateInitiated). How would the time be extracted for hours,
>> minutes and seconds?
>> Thanks!
>
> Would you believe HOUR() MINUTE() SECOND, or is that too obvious!
>
Re: How to extract Hour, Minute & Second
am 21.01.2007 17:29:37 von Olaf Doschke
Well, crossposting to
alt.php.sql,
microsoft.public.fox.vfp.queries-sql,
microsoft.public.sqlserver.misc
of course you get different answers
Bye, Olaf.
Re: How to extract Hour, Minute & Second
am 21.01.2007 17:35:02 von Dale
Thanks for all the help. Figured it out...here's what I did:
select convert(varchar(10), DateInitiated, 108)
....
....
"Dale" wrote in message
news:mfJsh.2144$jA.1625@bignews1.bellsouth.net...
>A table has a field containing the date and time. Example 2006-2-20
>08:11:44.123...field name is DateInitiated. I can extract the month, day
>and year by using Day(DateInitiated), Month(DateInitiated),
>Year(DateInitiated). How would the time be extracted for hours, minutes and
>seconds?
>
> Thanks!
>
Re: How to extract Hour, Minute & Second
am 21.01.2007 17:40:22 von Paul Lautman
Dale wrote:
> Well Paul, I did try that and here's the message that comes back...
>
> Server: Msg 195, Level 15, State 10, Line 1
> 'Hour' is not a recognized function name.
>
>
> "Paul Lautman" wrote in message
> news:51h5q7F1ipb3iU1@mid.individual.net...
>> Dale wrote:
>>> A table has a field containing the date and time. Example 2006-2-20
>>> 08:11:44.123...field name is DateInitiated. I can extract the month,
>>> day and year by using Day(DateInitiated), Month(DateInitiated),
>>> Year(DateInitiated). How would the time be extracted for hours,
>>> minutes and seconds?
>>> Thanks!
>>
>> Would you believe HOUR() MINUTE() SECOND, or is that too obvious!
I missed the other newsgroups in the title, you are obviously using
Microsoft SQL Server which, unlike DB/2 and MySQL does not have these other
useful functions.
You need the datepart function.
See http://msdn2.microsoft.com/en-us/library/aa258265(SQL.80).as px
Re: How to extract Hour, Minute & Second
am 21.01.2007 17:40:59 von Rik
Dale wrote:
> "Paul Lautman" wrote in message
> news:51h5q7F1ipb3iU1@mid.individual.net...
>> Dale wrote:
>>> A table has a field containing the date and time. Example 2006-2-20
>>> 08:11:44.123...field name is DateInitiated. I can extract the month,
>>> day and year by using Day(DateInitiated), Month(DateInitiated),
>>> Year(DateInitiated). How would the time be extracted for hours,
>>> minutes and seconds?
>>> Thanks!
>>
>> Would you believe HOUR() MINUTE() SECOND, or is that too obvious!
>
> Well Paul, I did try that and here's the message that comes back...
>
> Server: Msg 195, Level 15, State 10, Line 1
> 'Hour' is not a recognized function name.
Please don't toppost.
't would be in MySQL, I only just see you probably use MSSQL. Can you
please confirm this?
In that case, this is probably the answer:
http://doc.ddart.net/mssql/sql70/da-db_8.htm
So, DATEPART('hh',DateInitiated).
--
Rik Wasmus
Re: How to extract Hour, Minute & Second
am 21.01.2007 19:00:49 von Rik
Olaf Doschke wrote:
> Well, crossposting to
> alt.php.sql,
> microsoft.public.fox.vfp.queries-sql,
> microsoft.public.sqlserver.misc
>
> of course you get different answers
Another good reason not to crosspost :-) This question actually just
belongs to a single ng dedicated to the databaseserver in question.
--
Rik Wasmus