How to Get Current Date and Time in SQL?
In this article, we will show to get the current date and time in SQL. In SQL whenever we need to insert and fetching the Current date and time. So For finding to Current Date and Time in SQL have some Predefined function. We will Implement a few methods here. With the Help of the below function.
GET DATE() :
GETDATE() function is mostly used to find the current Date. It will return the DATETIME data type. This means it will Return the Current date with the current Time.
Select GetDate() AS 'CurrentDATETime';
It is also used to find current TIMESTAMP means current Date and Time. The CURRENT_TIMESTAMP function can be used the same that the GETDATE() function is used CURRENT_TIMESTAMP returns the same result as GETDATE().
Select CURRENT_TIMESTAMP AS "CURRENTTIMESTAMP";
SYSDATETIME() function is also used to get the current TIME of the System on which the instance of SQL Server is running. SYSDATETIME() function provides more fractional seconds precision compared to the GETDATE() function. We can fetch the TIME part from the DATE and TIME value returned from the SYSDATETIME() function as below:
SELECT SYSDATETIME() 'Current TIME using SYSDATETIME()'
Extract Time part alone from the current date from SYSDATE:
We can extract the time part from GETDATE() or CURRENT_TIMESTAMP().
SELECT CONVERT(VARCHAR(8), GETDATE(),108)'hh:mi:ss'