O'Reilly logo

SQL: Visual QuickStart Guide by Chris Fehily

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:
    CURRENT_DATE
    
    or To get the current time, type:
    CURRENT_TIME
    
    or To get the current time stamp, type:
    CURRENT_TIMESTAMP
    
    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).
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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required