Home > MS SQL > Format SQL Date hh:mm AM/PM

Format SQL Date hh:mm AM/PM

SELECT RIGHT( convert(varchar(25),GETDATE(),101)  +’ ‘+ CASE WHEN DATEPART(HH,GETDATE()) < 13 THEN RIGHT(REPLICATE(‘0’,2) + CAST(datepart( HH,GETDATE()) AS VARCHAR(2)),2) ELSE RIGHT(REPLICATE(‘0′,2) + CAST(datepart( HH, dateadd(HH, -12 ,GETDATE())) AS VARCHAR(2)),2) END +’:’+ RIGHT(REPLICATE(‘0′,2) + CAST(datepart( mi,GETDATE()) AS VARCHAR(2)),2) +’ ‘+ CASE WHEN DATEPART(HH,GETDATE()) < 13 THEN ‘AM’ ELSE ‘PM’ END,8)

Got a big sql statement to show the time format (hh:mm AM/PM) from date.

If any simple query to do it, please let me know.

🙂

Advertisements
Categories: MS SQL
  1. March 16, 2013 at 11:41 am

    awesome code… u r a genious xDDDD

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: