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
- Open a new query in SSMS > Drop the following query to show the data in Hijri format.
SELECT CONVERT(VARCHAR(30),GETDATE(),131) AS DateConvert;
Output
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 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)
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
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
Applied To
- SQL Server
See Also
- Get the Detailed Information Via SERVERPROPERTY.
- Get the first record added per day group by the user in SQL.
- Get the last record added per day group by the user in SQL.
- SQL Server: How to get the current installed update level.
- How to convert Gregorian dates to Hijri date in SQL Server.
Have a Question?
If you have any related questions, please don’t hesitate to ask it at deBUG.to Community.