GETDATE() in SQL
Returns the current date and time of the database server.
Syntax
Return type
GETDATE() Function Example
What is GETDATE() in SQL?
The GETDATE()
function in SQL returns the current date and time based on the database server’s system clock. It is commonly used for timestamping records, logging events, and scheduling tasks. The function returns a datetime value that includes both the date (YYYY-MM-DD) and the time (HH:MI:SS).
GETDATE()
is primarily used in SQL Server. For similar functionality in other databases:
MySQL & PostgreSQL use
NOW()
.Oracle uses
SYSDATE()
.SQLite uses
DATETIME('now')
.
This function is widely applied in audit trails, real-time data processing, and transaction logging.
Parameters:
None - takes no parameters
Example Use Cases:
-- Log transaction time
-- Find records from today
-- Calculate time differences
Notes:
Behavior: Returns server timestamp, not client time
Performance Considerations: Non-deterministic function
Version Info: Core function with different names across DBMS
Deprecated/Recommended Alternatives: SYSDATETIME() in some DBMS for higher precision
Error Handling:
Error: Rarely throws errors as it's a system function
Recommendation: Use TRY_CONVERT for type conversions
Supported Databases:
DBMS
Function / Syntax
Example
Behavior with NULL
MySQL
NOW(), CURRENT_TIMESTAMP()
NOW()
Never NULL
PostgreSQL
CURRENT_TIMESTAMP, NOW()
CURRENT_TIMESTAMP
Never NULL
SQL Server
GETDATE(), CURRENT_TIMESTAMP
GETDATE()
Never NULL
SQLite
datetime('now')
datetime('now')
Never NULL
BigQuery
CURRENT_TIMESTAMP()
CURRENT_TIMESTAMP()
Never NULL
Snowflake
CURRENT_TIMESTAMP()
CURRENT_TIMESTAMP()
Never NULL
Athena
CURRENT_TIMESTAMP
CURRENT_TIMESTAMP
Never NULL