DB2 Scalar functions - DATE_PART
The DATE_PART function returns a portion of a datetime based on its arguments. It extracts the subfield that is specified from the date, time, timestamp, and duration values.
The schema is SYSIBM.
Valid for DATE, TIME, and TIMESTAMP.
Valid for DATE, TIMESTAMP, date duration, and timestamp duration.
Valid for DATE, TIMESTAMP, date duration , timestamp duration.
The number of the month within the year (1 - 12).
The number of the week of the year (1 - 53) that the specified day is in. The value uses the ISO-8601 definition of a week, which begins on Monday; as a result, some years might have 53 weeks, and sometimes the first few days of January can be included as part of the 52nd or 53rd week of the previous year.
Valid for DATE and TIMESTAMP.
The day of the month (1 - 31).
The day of the week, from 1 (Sunday) to 7 (Saturday).
The day of the year (1 - 366).
The hour of the day (0 – 23).
Valid for TIME, TIMESTAMP, time duration, and timestamp duration.
The minute of the hour (0 – 59).
The second of the minute, not including fractional parts (0 – 59).
The second of the minute, including fractional parts to one thousandth of a second, multiplied by 1000 (0 – 59999).
Valid for TIMESTAMP and timestamp duration.
The second of the minute, including fractional parts to one millionth of a second, multiplied by 1000000 (0 – 59999999).
The format-string values are case insensitive.
The data type of the result of this function is BIGINT. If the argument can be null, the result can be null; if the argument is null, the result is the null value.
values DATE_PART('DAY', DATE('2007-02-18')); Result: 18
values DATE_PART('YEAR', cast(20130710 as decimal(8,0))); Result: 2013
values DATE_PART('HOUR', cast(075559 as decimal(6,0))); Result: 7