How to Get the Current Date and Time in SQL

To get the current date and time in SQL, use the GETDATE() function. This function takes no arguments and returns the current date and time as a datetime value. For example, if you wanted to get the current date and time, you would use the following query:

SELECT GETDATE();

Examples

Let's look at a few examples of how this function can be used. Suppose you have a table called orders with the following data:

orders
order_idorder_date
12020-01-01
22020-01-02
32020-01-03


If you wanted to get the current date and time and add it to the orders table, you would use the following query:

INSERT INTO orders (order_date) VALUES (GETDATE());

This query would add a new row to the orders table with the current date and time as the order_date value. 🤗

Additional Info

The GETDATE() function is supported by most major databases, including MySQL, PostgreSQL, and SQL Server. However, the syntax may vary slightly depending on the database you are using. For more information, check out the documentation for your particular database.

Want to build your own LLM Apps with AirOps👇👇