Getting the Current Date and Time
Use the CURRENT_DATE, CURRENT_TIME, and CURRENT_TIMESTAMP functions to get the current date and time from the system clock of the particular computer where the DBMS is running.
To get the current date and time:
- To get the current date, type:
or To get the current time, type:
CURRENT_DATE
or To get the current time stamp, type:CURRENT_TIME
CURRENT_DATE returns a DATE, CURRENT_TIME returns a TIME, and CURRENT_TIMESTAMP returns a TIMESTAMP; see “Datetime Types” in Chapter 3 (Listings 5.25 and 5.26, Figures 5.25 and 5.26).CURRENT_TIMESTAMP
Listing 5.25. Print the current date, time, and time stamp. See Figure 5.25 for the result.
SELECT CURRENT_DATE AS "Date", CURRENT_TIME AS "Time", CURRENT_TIMESTAMP ... |
Get SQL: Visual QuickStart Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.