Format date with AM PM and without second in SQL Server 2012

 In this post, I will explain How to format date with AM PM and without second in SQL Server


Format date with AM PM and without second in SQL Server

Get current Hijri date in SQL

SELECT CONVERT(VARCHAR(30),GETDATE(),131) AS DateConvert;

Output

Get current Hijri date in SQL

Get current Hijri date without seconds in SQL

  • Format the date with only Hour and Minute via
select convert(nvarchar(16),GetDate(),131)

Output(Query 1)

Get current Hijri date without seconds in SQL

Get only AM or PM in SQL

  • to Get only AM or PM, run the below query
Select substring(convert(varchar(30), GetDate(), 9), 25, 2)

Output(Query 2)

Get only AM or PM in SQL

Concatenate Query 1 with Query 2 to get the required format.

select convert(nvarchar(16),GetDate(),131) 
+ ' ' + substring(convert(varchar(30), GetDate(), 9), 25, 2)

Output

Format date with AM PM and without second in SQL Server
Format date with AM PM and without second in SQL Server 2012

Get current Time without seconds in SQL

To get only HH:mm AM/PM format, you would use the following query

SELECT substring(convert(varchar(20), GetDate(), 9), 13, 5) 
+ ' ' + substring(convert(varchar(30), GetDate(), 9), 25, 2)

Output

Get current Time without seconds in SQL

Applied To

  • SQL Server
See Also
Have a Question?

If you have any related questions, please don’t hesitate to ask it at deBUG.to Community.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top