Hi,
I am looking to get the date time (GETUTCDATE()) In following 12 hours format: DD-MON-YYYY HH:MM:SS AM/PM
Eg: 13-DEC-2018 03:10:58 PM
Is there any way of getting this rather than extracting datepart and manipulating them?
Hi,
I am looking to get the date time (GETUTCDATE()) In following 12 hours format: DD-MON-YYYY HH:MM:SS AM/PM
Eg: 13-DEC-2018 03:10:58 PM
Is there any way of getting this rather than extracting datepart and manipulating them?
convert function using date format
Ya, I have seen this link and several similar ones. But if you notice none of them has the format which I am looking for: DD-MON-YYYY HH:MM:SS AM/PM
Eg: 13-DEC-2018 03:10:58 PM
Also, below code shows all the formats which are supported by SQL Server but they doesn't seem to be matching the one which i am looking for:
DECLARE @counter INT = 0
DECLARE @date DATETIME = GETUTCDATE()
CREATE TABLE #dateFormats (dateFormatOption int, dateOutput varchar(40))
WHILE (@counter <= 150 )
BEGIN
BEGIN TRY
INSERT INTO #dateFormats
SELECT CONVERT(varchar, @counter), CONVERT(varchar,@date, @counter)
SET @counter = @counter + 1
END TRY
BEGIN CATCH;
SET @counter = @counter + 1
IF @counter >= 150
BEGIN
BREAK
END
END CATCH
END
SELECT * FROM #dateFormats
You can use this - but warning...it will probably not perform very well. There are known performance issues related to using FORMAT.
Select format(getutcdate(), 'dd-MMM-yyyy hh:mm:ss tt')
One advantage to format though - you can include the culture parameter.