Skip to main content
Log inGet a demo
← SQL Dictionary
Date functions

SQL CURTIME

What is SQL CURTIME?

The SQL CURTIME() function is used to retrieve the current time in the format HH:MM:SS, where HH represents hours (00-23), MM represents minutes (00-59), and SS represents seconds (00-59). It returns the current time based on the server's system clock.

When You Would Use It

You would use the CURTIME() function when you need to work with the current time within your SQL queries or statements. Common use cases include recording timestamps, scheduling events, calculating time differences, or filtering data based on the current time.

Syntax

The syntax of the SQL CURTIME() function is straightforward:

CURTIME()

Parameter Values

The CURTIME() function does not require any parameters. It returns the current time as a time data type.

Example Query

Here's an example of how you might use the CURTIME() function in a SQL query to insert a new record with the current time:

INSERT INTO Log (Event, EventTime)
VALUES ('User login', CURTIME());

In this example, the CURTIME() function retrieves the current time, which is then inserted into the "EventTime" column of the "Log" table along with an event description.

Example Table Response

If you query the "Log" table after executing the above INSERT statement, it might look something like this:

EventEventTime
User login15:30:45

The "EventTime" column would contain the current time when the record was inserted.

Use Cases

The SQL CURTIME() function is useful for various scenarios, including:

  1. Timestamping records: To record the time when a particular event occurred.
  2. Scheduling events: To schedule tasks, reminders, or events in the database based on the current time.
  3. Calculating time differences: To measure the time between two timestamps.
  4. Time-based filtering: To retrieve records based on their time values.

SQL Languages This Is Available For

The CURTIME() function is available in many popular SQL database management systems, but the naming and implementation may vary slightly. Common variations include:

  • MySQL: CURTIME()
  • PostgreSQL: CURRENT_TIME
  • SQLite: time('now')
  • SQL Server: GETDATE()
  • Oracle: SYSTIMESTAMP
  • DB2: CURRENT TIME

While the fundamental functionality remains consistent, it's crucial to consult the documentation for your specific database management system to ensure you are using the correct function and understand any differences in formatting or behavior.


Keep reading

SQL CURDATE

Read article

SQL DATEPART

Read article

SQL EXTRACT

Read article

Ready to put your SQL knowledge to work?

Practice writing SQL to call data from the warehouse and sync it into Google Sheets in this 5 minute interactive demo.

Hightouch Audiences user interface.