DB2 development common date functions get time 1. Get current date: values current date; 2012-08-28 www.2cto.com 2. Get current time values current time; 11:56:36. Get current timestamp; 11:57:32 4, year () Get the current year values year (current timestamp); 2012 5, month () Get the current month values month (current timestamp); 8 6, day () get the current day values day (current timestamp); 28 www.2cto.com 7, hour () Get the current time values hour (current timestamp); 12 8, minute () obtain the current value of values minute (current timestamp); 3 9. Obtain the second value of values second (current timestamp); 48 10. Obtain the millisecond value of values microsecond (current timestamp ); 59000 11. Convert timestamp to varchar values varchar_format (current timestamp, 'yyyy-mm-dd hh24-mm-ss '); extract date values date (current timestamp) from 2012-08-28 12-08-21 12 and timestamp; extract time www.2cto.com values time (current timestamp) from 2012-08-28 13 and timestamp ); 12:14:51. The Dayname () related to the week returns the day of the week in the date parameter. Return Value Type: String. For example: Monday values dayname (current timestamp); Tuesday Dayofweek () return the day of the week in the date parameter. Return Value Type: integer. For example: 1. 1 indicates Sunday values dayofweek (current timestamp); 3 ---- today is Tuesday Dayofweek_iso () return the day of the Week in the date parameter. Return Value Type: integer. For example, 1 indicates Monday values dayofweek_iso (current timestamp); 2 ---- today is Tuesday Week () returns the week of the year in the date parameter, and returns an integer in the range of (1-54, take Sunday as the week's start values Week (timestamp ('2017-1-8 '); 2 week () returns the Week of the year in which the date parameter is located, returns an integer in the range of (1-53). Monday is used as the start values week_iso (timestamp ('2017-1-8 ') of a week ')); 1 www.2cto.com 15. Convert Varchar_format (<time>, 'yyyy-mm-dd') between time and string. Return Value: string values varchar_format (current timestamp, 'yyyy-mm-dd hh24-mm-ss '); 2012-08-28 12-08-37 To_char () values to_char (current timestamp); Aug 28,201 2 12:37:33 PM Char () values char (current timestamp); 2012-08-28-12.38.10.387000 values char (time ('22: 24: 23'); 22.24.23 string to Date or time Date () values date ('2017-1-1 '); 2012-01-01 Time () values time ('22. 22.22 '); 22:22:22 Timestamp () values timestamp ('2017-1-1-22.42.23.000890'); 2012 22:42:23 16. Calculate the value current date + 1 year + 2 months + 4 days; ----- 17. Time Difference Calculation Timestampdiff () Prerequisites: 1. Skip the year; 2. Assume that there are only 30 days, 1 = seconds of decimal part, 2 = seconds www.2cto.com 4 = Minute 8 = hour 16 = days 32 = weeks 64 = months 128 = quarter 256 = year timestampdiff (2, char (current timestamp-timestamp (task. create _) exact calculation () Return Value: INTEGER (DAYS (<timestamp1>)-DAYS (<timestamp2>) * 86400 + (MIDNIGHT_SECONDS (<timestamp1>) -MIDNIGHT_SECONDS (<timestamp2> ))