How to Get the Current Time in SQL

Use the CURRENT_TIMESTAMP function to find the current time using SQL. This function returns the current date and time as a timestamp value. For example, if you wanted to get the current time in SQL, you would use the following query:

SELECT CURRENT_TIMESTAMP;

Examples

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

transactions
transcation_idamounttime
110.002020-01-01 12:00:00
220.002020-01-02 13:00:00
330.002020-01-03 14:00:00

If you wanted to add a new transaction with the current time, you would use the following query:

INSERT INTO transactions (amount, time) VALUES (40.00, CURRENT_TIMESTAMP);

Additional Info

The CURRENT_TIMESTAMP 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👇👇