The following is compiled from the DB2 Foundation: use of dates and times
1. Use SQL to get the current timestamp of the database server
- SELECT current date from sysibm.sysdummy1
- SELECT current time from sysibm.sysdummy1
- SELECT current timestamp from sysibm.sysdummy1
description : The SYSIBM.SYSDUMMY1 table is a special in-memory table that can be used to display the value of the DB2 register as shown above. Here, the current date, the current time, and current timestamp are the names of the special registers of the DB2.
In addition to using SQL, you can use the keyword values to evaluate a register or an expression. For example, on the DB2 command line PROCESSOR,CLP, enter the following command:
- VALUES Current date
- VALUES Current time
- VALUES Current timestamp
description : Another way to use the register name of current date, current time, current timestamp, etc. is current_date, Current_time, Current_ Timestamp
2. Use current timezone register to adjust GMT or cut time zone
- Current time-current timezone
- Current timestamp-current timezone
Note : The current timezone is also a special register of the DB2, as is the register with the present time, and its value is the correction value of the currently timezone.
3. Use the function to extract the year, month, day, time, minute, second and microsecond
- Year (current timestamp)
- MONTH (current timestamp)
- Day (current timestamp)
- HOUR (current timestamp)
- MINUTE (current timestamp)
- SECOND (current timestamp)
- Microsecond (current timestamp)
Extract date and time from timestamp
- DATE (current timestamp)
- Time (current timestamp)
4. Use English to perform date and time calculations
- Current date + 1 year
- Current date + 3 years + 2 MONTHS +
- Current time + 5 HOURS-3 MINUTES + SECONDS
Not finished ...
DB2 time operation