Home All Groups Group Topic Archive Search About

Select time frorm smalldatetime

Author
15 Sep 2005 2:30 PM
Aleks
How can I select the time only from a smalldatetime field ?

Field is called 'dateinitiated'

Thanks in advance,

Aleks

Author
15 Sep 2005 2:39 PM
Alejandro Mesa
See function "convert" in BOL.

Example:

select convert(varchar(25), getdate(), 108)


AMB

Show quote
"Aleks" wrote:

> How can I select the time only from a smalldatetime field ?
>
> Field is called 'dateinitiated'
>
> Thanks in advance,
>
> Aleks
>
>
>
Author
15 Sep 2005 2:48 PM
Aleks
Thanks guys, it worked.

A


Show quote
"Alejandro Mesa" <AlejandroM***@discussions.microsoft.com> wrote in message
news:6D3F24E0-1405-4D6D-8B3F-ACE466B79AC4@microsoft.com...
> See function "convert" in BOL.
>
> Example:
>
> select convert(varchar(25), getdate(), 108)
>
>
> AMB
>
> "Aleks" wrote:
>
>> How can I select the time only from a smalldatetime field ?
>>
>> Field is called 'dateinitiated'
>>
>> Thanks in advance,
>>
>> Aleks
>>
>>
>>
Author
15 Sep 2005 2:45 PM
Bob Barrows [MVP]
Aleks wrote:
> How can I select the time only from a smalldatetime field ?
>
> Field is called 'dateinitiated'
>
> Thanks in advance,
>
There is a good article in Books Online (BOL) called "Using Date and Time
data". You should definitely look it up.

The answer depends on what you want to do with the "time" extracted from the
smalldatetime. if you simply want a string containing the time, then

SELECT CONVERT(varchar(20),dateinitiated,108) FROM ...

If you wish to perform calculations with the resulting value, then a
different solution is needed.

While you're in BOL reading about the CONVERT function, also look up the
DATEPART, DATEADD, and other date/time functions found in the Transact-SQL
Reference..

Bob Barrows

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

AddThis Social Bookmark Button