Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to Get Current Date and Time in SQL?

  • Last Updated : 08 Oct, 2021

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.

Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course  by GeeksforGeeks.

Query:

Select GetDate() AS 'CurrentDATETime';



Output:

CURRENT_TIMESTAMP:

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(). 

Query:

Select CURRENT_TIMESTAMP AS "CURRENTTIMESTAMP"; 

Output:



SYSDATETIME()

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:

Query:

SELECT SYSDATETIME() 'Current TIME using SYSDATETIME()'

Output:

Extract Time part alone from the current date from SYSDATE:

 We can extract the time part from GETDATE() or CURRENT_TIMESTAMP().

Query:

SELECT CONVERT(VARCHAR(8), GETDATE(),108)'hh:mi:ss'

Output:

 

My Personal Notes arrow_drop_up
Recommended Articles
Page :