Common date operation functions of IBM DB2 database "big face"

Source: Internet
Author: User
Tags db2 date ibm db2 ibm db2 database

The following articles mainly describe the common date operation functions of the IBM DB2 database and the correct operation steps for the common date operation functions of the IBM DB2 database, we start from the current time of the DB2 date operation function.

DB2 date operation functions

Current Time:

 
 
  1. CURRENT DATE   
  2. CURRENT TIME   
  3. CURRENT TIMESTAMP   

Obtain the year, month, day, hour, minute, second, And microsecond parts of the time:

 
 
  1. YEAR (current timestamp)   
  2. MONTH (current timestamp)   
  3. DAY (current timestamp)   
  4. HOUR (current timestamp)   
  5. MINUTE (current timestamp)   
  6. SECOND (current timestamp)   
  7. MICROSECOND (current timestamp)   

Addition and subtraction of time:

 
 
  1. current date + 1 YEAR   
  2. current date + 3 YEARS + 2 MONTHS + 15 DAYS   
  3. current time + 5 HOURS - 3 MINUTES + 10 SECONDS   

To calculate the number of days between two dates, you can subtract the date:

 
 
  1. days (current date) - days (date('1999-10-22'))   

Convert time to string:

 
 
  1. char(current date)  

String to time:

TIMESTAMP (), DATE (), and TIME (). For supported string formats, see help. oracle to_date is not flexible.

 
 
  1. Date('2005-01-01')  

Some functions of date and time:

DAYNAME returns a string of both upper and lower cases. For the day part of the parameter, the name of the day is represented by week, for example, Friday ).

DAYOFWEEK returns the day of the week in the parameter, expressed by an integer ranging from 1 to 7, where 1 represents Sunday.

DAYOFWEEK_ISO returns the day of the week in the parameter, expressed by an integer ranging from 1 to 7, where 1 represents Monday.

DAYOFYEAR returns the day of the year in the parameter, expressed by an integer ranging from 1 to 366.

DAYS returns an integer of the date.

JULIAN_DAY returns the number of days from the start date of the rulecalendar on January 1, January 1, 4712 BC to the specified date value in the parameter, expressed in an integer.

MIDNIGHT_SECONDS returns the number of seconds between midnight and the specified time value in the parameter, which is expressed by an integer ranging from 0 to 86400.

MONTHNAME returns a string, such as January, in combination with upper and lower cases, for the month of the parameter month ).

TIMESTAMP_ISO returns a time stamp Value Based on the date, time, or time stamp parameter.

TIMESTAMP_FORMAT returns a timestamp from a string interpreted using a character template.

TIMESTAMPDIFF returns the estimated time difference expressed by the type defined by the first parameter based on the time difference between the two timestamps.

TO_CHAR returns the time stamp character representation formatted using the character template. TO_CHAR is a synonym for VARCHAR_FORMAT.

TO_DATE returns a timestamp from a string that has been interpreted using a character template. TO_DATE is a synonym for TIMESTAMP_FORMAT.

WEEK returns the WEEK number of the year in the parameter, expressed by an integer ranging from 1 to 54. Start from Sunday.

WEEK_ISO returns the week of the year in the parameter, which is expressed by an integer ranging from 1 to 53.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.