How to get the current system time only in SQL Server / any database.
The date is not required...only the current time is required.
How to get the current system time only in SQL Server / any database.
The date is not required...only the current time is required.
You can use getdate()
or current_timestamp
This will give you both date and time but then you can format it however you need.
If you are using SQL Server 2008+ you can even format the result as time
:
select cast(getdate() as time)
If you are not in SQL Server 2008+, then you can use many different methods to get the time only including:
SELECT convert(char(8), getdate(), 108)
See SQL fiddle demo with several versions
Using `getdate()` like:
select getdate()
=============================
and get only time use convert function with 108 code like :
select convert(varchar,GETDATE(),108)
There is 3 different statement available to get the current system time
select CONVERT(VARCHAR(8),getDate(),108)
select CONVERT(VARCHAR(8),{fn NOW()},108)
select CONVERT(VARCHAR(8),CURRENT_TIMESTAMP,108)
They all produce the same results and performance are the same, therefore it is really whatever one of the three you prefer the look of.