How to Get the Current Date in SQL?

Learn via video course
FREE
View all courses
DBMS Course - Master the Fundamentals and Advanced Concepts
DBMS Course - Master the Fundamentals and Advanced Concepts
by Srikanth Varma
1000
5
Start Learning
DBMS Course - Master the Fundamentals and Advanced Concepts
DBMS Course - Master the Fundamentals and Advanced Concepts
by Srikanth Varma
1000
5
Start Learning
Topics Covered

To get just the current date in SQL, a multitude of different functions could be used. The GETDATE() function, SYSDATETIME() function, and CURRENT_TIMESTAMP() function is a few of the in-built functions that SQL could leverage. These are used to display the current date or time or both of the systems.

In this article, we talk about each of these functions in detail.

To get the current date in SQL, the GETDATE() function is the most commonly used function.

However, it is important to note that the GETDATE() function for retrieving the current date in SQL returns both the current date and time. Therefore, to print just the date, the CAST() function could be used to cast away the time returned and display only the date. It converts the datetime data type into just the date data type.

Insert Current Date in SQL

To insert the value of the current date in SQL, we can use the curdate() method.

First, a table needs to be created to retrieve the datetime column :

Now, that the table has been created, the curdate() method could be used to push the values of the system's current date and time into the table InsertDate :

Now to obtain the output, all one has to do is query the DateTodayrecord from the table.

Example Using Current Date in SQL

The pre-defined SQL functions GETDATE(), CURRENT_TIMESTAMP, and SYSDATETIME() return output values in the datetime format. The CAST() function could be used only to cast away the time values and produce strictly date values.

The output for this code is going to be the current date.

example-using-current-date-1

The CURRENT_TIMESTAMP() function could be used interchangeably with the GETDATE() function.

example-using-current-date-2

This is also going to display both the date and the time together. So, the CAST() function may be called again.

example-using-current-date-3

The SYSDATETIME() function could also be used to return the date and time of the system.

example-using-current-date-4

Conclusion

  1. The current date in SQL could be used to retrieve the date values in SQL.
  2. A number of functions such as GETDATE(), SYSDATETIME(), CURDATE(), CURRENT_TIMESTAMEP() could be used to obtain the date values.
  3. All these functions could be used interchangeably.
  4. The CAST() function could be used to change the datetime outputs to only dates.
  5. The current date in SQL could also be inserted into the system by creating a table and inserting curdate() values into it.

Learn More