How to get the Time in HH:MM AM PM format IN SQL Server

How to get time in AM PM format in SQL Server

How to get time in 12 hour format in SQL Server






SELECT CONVERT(VARCHAR,GETDATE(),100) as ‘Default Date format’

SELECT RIGHT(‘0’+LTRIM(RIGHT(CONVERT(varchar,getDate(),100),8)),7) as ’12 Hour Time in AMPM’

SELECT REPLACE(REPLACE(RIGHT(‘0’+LTRIM(RIGHT(CONVERT(varchar,getdate(),100),7)),7),’AM’,’ AM’),’PM’,’ PM’)

as ’12 Hour Time in AM PM’

Advertisements
Posted in: SQL

One thought on “How to get the Time in HH:MM AM PM format IN SQL Server

  1. Karthik Mani says:

    Instead of Replace we can use STUFF()
    Try this
    SELECT STUFF(RIGHT(‘0’+LTRIM(RIGHT(CONVERT(varchar,getdate(),100),7)),7),6,0,’ ‘)

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