Reputation: 7377
How do I get the current time only?
select getdate()
Gives me:
Dec 16 2016 5:41PM
I want this result:
5:41PM
Upvotes: 8
Views: 24578
Reputation: 49
This query returns time with format "hh:mm:ss" :
Select Convert(Time(0), GetDate())
Upvotes: 1
Reputation: 41
And if using Sybase ASE 15+ you can use the current_time() function.
select current_time() -- returns 'time' datatype
You can also use the normal date/time-related and convert/cast functions against the resulting value as needed (eg, changing output format).
Upvotes: 2
Reputation: 1972
If you need it in 12-hour format you can use CONVERT:
SELECT LTRIM(RIGHT(CONVERT(VARCHAR(50), GETDATE(), 100), 7))
Otherwise the CAST to TIME is simpler.
Upvotes: 0
Reputation: 16917
You can convert the GETDATE()
results to a TIME
datatype to pull the current time:
Select Convert(Time, GetDate())
Upvotes: 14
Reputation: 112
You can do that pretty simply; if I correctly understood your problem.
SELECT CAST('INSERT THE TIME HERE' AS TIME(0))
Upvotes: 2