SQL CURRENT_TIME function
Returns the current time of day. The standard keyword is CURRENT_TIME; SQL Server casts a timestamp to time, and Oracle, which has no TIME type, formats one as text.
- Catégorie
- Dates & times
- Returns
time (time with time zone on PostgreSQL)- In this category
- 16 of 121
Syntaxe
CURRENT_TIME
CURRENT_TIME(p)
CURTIME() -- MySQL
Each block is a separate form. The support table and the examples show which engine takes which.
Prise en charge des moteurs
| Moteur | Support | Notes |
|---|---|---|
| SQL Server | Different name or syntax | CAST(SYSDATETIME() AS time) |
| PostgreSQL | Oui | returns time with time zone; LOCALTIME returns plain time |
| MySQL | Oui | Supported under this name. |
| SQLite | Oui | UTC text 'HH:MM:SS'; no precision argument |
| Oracle | Not built in | no TIME type; TO_CHAR(SYSDATE, 'HH24:MI:SS') gives text |
Exemples
PostgreSQL
SELECT CURRENT_TIME(3) AS now_time;
MySQL
SELECT CURTIME() AS now_time;
SQL Server
SELECT CAST(SYSDATETIME() AS time) AS now_time;
Bon à savoir
- SQLite's CURRENT_TIME is UTC; time('now', 'localtime') gives the local wall clock.
- PostgreSQL's CURRENT_TIME returns time with time zone, a type its own docs advise against storing. LOCALTIME returns plain time.
- Precision differs: PostgreSQL takes CURRENT_TIME(3), MySQL takes CURTIME(3) or CURRENT_TIME(3), and SQLite rejects a precision argument.
Questions about CURRENT_TIME
Does SQL Server have CURRENT_TIME?
No. CAST(SYSDATETIME() AS time) or CAST(GETDATE() AS time) returns just the time of day.
Why is SQLite's CURRENT_TIME off by hours?
It returns UTC. If you need the local wall clock, use strftime('%H:%M:%S','now','localtime').
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, SQLite.
Functions your engine actually has
SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.