Is there a way to get the 3 digit month name like Dec from GETDATE() or any
date?SELECT Left(DateName(m, <DateColumn> ),3) FROM <TableName>
"Scott" <sbailey@.mileslumber.com> wrote in message
news:echrOus$FHA.3104@.TK2MSFTNGP15.phx.gbl...
> Is there a way to get the 3 digit month name like Dec from GETDATE() or
> any date?
>|||Scott,
Just to cover all bases, note that the short month is not
necessarily three characters long, if one allows the possibility
of any language setting. If you need the "short month", regardless
of its length, you can parse it out of
select shortmonths from master..syslanguages where langid = @.@.langid
or you can get it indirectly this way:
select
left(
convert(nvarchar(30),getdate(),9),
charindex(space(1),convert(varchar,getda
te(),9))-1) as ShortMonth
Steve Kass
Drew University
Scott wrote:
>Is there a way to get the 3 digit month name like Dec from GETDATE() or any
>date?
>
>|||SELECT CONVERT(CHAR(3), DATENAME(MONTH, GETDATE()))
"Scott" <sbailey@.mileslumber.com> wrote in message
news:echrOus$FHA.3104@.TK2MSFTNGP15.phx.gbl...
> Is there a way to get the 3 digit month name like Dec from GETDATE() or
> any date?
>
Showing posts with label getdate. Show all posts
Showing posts with label getdate. Show all posts
Thursday, March 29, 2012
Extract hh AM/PM from getdate()
Hi,
I am looking for a query to extract hour and AM or PM value from a date on sql2000.
ex/-
Input : 2001-12-28 22:18:07.810 (from getdate())
Output : 10 PM
select convert(varchar, (datepart(hh, convert(varchar, getdate(), 8)) % 12)) + ' ' +
substring (convert(varchar, convert(datetime, getdate(),20), 100),
DATALENGTH(convert(varchar, convert(datetime, getdate(),20), 100)) - 1,
DATALENGTH(convert(varchar, convert(datetime, getdate(),20), 100 )))
The above works but is there a better way to do this?This is a little shorter:
SELECT CONVERT(VARCHAR,DATEPART(hh,GETDATE())%12) +
CASE WHEN (DATEPART(hh,GETDATE())%12) > 0 THEN ' PM' ELSE ' AM' END|||thanks for your reply.
but i figured that 12 AM or 12 PM was displayed as 0 AM and 0 PM.
Hence to reduce my troubles, i will stick with the good ol' substring.
SELECT (substring(CONVERT(VARCHAR,getdate(),22),10,2) + ' ' +
substring(CONVERT(VARCHAR,getdate(),22), 19,2))
I am looking for a query to extract hour and AM or PM value from a date on sql2000.
ex/-
Input : 2001-12-28 22:18:07.810 (from getdate())
Output : 10 PM
select convert(varchar, (datepart(hh, convert(varchar, getdate(), 8)) % 12)) + ' ' +
substring (convert(varchar, convert(datetime, getdate(),20), 100),
DATALENGTH(convert(varchar, convert(datetime, getdate(),20), 100)) - 1,
DATALENGTH(convert(varchar, convert(datetime, getdate(),20), 100 )))
The above works but is there a better way to do this?This is a little shorter:
SELECT CONVERT(VARCHAR,DATEPART(hh,GETDATE())%12) +
CASE WHEN (DATEPART(hh,GETDATE())%12) > 0 THEN ' PM' ELSE ' AM' END|||thanks for your reply.
but i figured that 12 AM or 12 PM was displayed as 0 AM and 0 PM.
Hence to reduce my troubles, i will stick with the good ol' substring.
SELECT (substring(CONVERT(VARCHAR,getdate(),22),10,2) + ' ' +
substring(CONVERT(VARCHAR,getdate(),22), 19,2))
Subscribe to:
Posts (Atom)