Skip to content Skip to sidebar Skip to footer

Get Time From Getdate()

I would like to take the Getdate() results of, for example 2011-10-05 11:26:55.000 into 11:26:55 AM I have looked other places and found Select RIGHT(CONVERT(VARCHAR, GETDATE()

Solution 1:

select convert(varchar(10), GETDATE(), 108)

returned 17:36:56 when I ran it a few moments ago.

Solution 2:

You might want to check out this old thread.

If you can omit AM/PM portion and using SQL Server 2008, you should go with the approach suggested here

To get the rid from nenoseconds in time(SQL Server 2008), do as below :

SELECT CONVERT(TIME(0),GETDATE()) AS HourMinuteSecond

I hope it helps!!

Solution 3:

Did you try to make a cast from date to time?

select cast(getdate() as time)

Reviewing the question, I saw the 'AM/PM' at end. So, my answer for this question is:

select format(getdate(), 'hh:mm:ss tt')

Run on Microsoft SQL Server 2012 and Later.

Solution 4:

To get the format you want:

SELECT (substring(CONVERT(VARCHAR,GETDATE(),22),10,8) + ' ' + SUBSTRING(CONVERT(VARCHAR,getdate(),22), 19,2))

Why are you pulling this from sql?

Solution 5:

Let's try this

selectconvert(varchar, getdate(), 108) 

Just try a few moment ago

Post a Comment for "Get Time From Getdate()"