DB2 Time Functions

Source: Internet
Author: User

DB2 time functions are one of our most common functions. The following describes some DB2 time functions for your reference. We hope you can learn more about DB2 time functions.

 
 
  1. -- Get the current date:
  2.  
  3. Select current date from sysibm. sysdummy1;
  4. Values current date;
  5.  
  6. -- Get the current date
  7. Select current time from sysibm. sysdummy1;
  8. Values current time;
  9. -- Get the current Timestamp
  10. Select current timestamp from sysibm. sysdummy1;
  11. Values current timestamp;
  12.  
  13. -- To adjust the current time or current time stamp to GMT/CUT, subtract the current time or time stamp from the current time zone register:
  14.  
  15. Values current time-current timezone;
  16. Values current timestamp-current timezone;
  17.  
  18. -- Get the current year
  19.  
  20. Values year (current timestamp );
  21.  
  22. -- Get the current month
  23. Values month (current timestamp );
  24.  
  25. -- Get the current day
  26. Values day (current timestamp );
  27.  
  28. -- Get current time
  29. Values hour (current timestamp );
  30.  
  31. -- Get minutes
  32. Values minute (current timestamp );
  33.  
  34. -- Get seconds
  35. Values second (current timestamp );
  36.  
  37. -- Get millisecond
  38. Values microsecond (current timestamp );
  39.  
  40. -- Extract the date and time from the time stamp
  41.  
  42. Values date (current timestamp );
  43. Values VARCHAR_FORMAT (current TIMESTAMP, 'yyyy-mm-dd ');
  44. Values char (current date );
  45. Values time (current timestamp );
  46.  
  47. -- Calculate the execution date and time
  48.  
  49. Values current date + 1 year;
  50. Values current date + 3 years + 2 months + 15 days;
  51. Values current time + 5 hours-3 minutes + 10 seconds;
  52.  
  53. -- Calculate the number of days between two dates
  54.  
  55. Values days (current date)-days (date ('1970-02-20 '));
  56.  
  57. -- Replace time and date with a string
  58.  
  59. Values char (current date );
  60. Values char (current time );
  61.  
  62. -- Converts a string to a date or time value.
  63.  
  64. Values timestamp ('2017-03-09-22.43.00.000000 ');
  65. Values timestamp ('2017-03-09 22:44:36 ');
  66. Values date ('2017-03-09 ');
  67. Values date ('2014/1/123 ');
  68. Values time ('22: 45: 27 ');
  69. Values time ('22. 45.27 ');
  70.  
  71. -- Calculate the time difference between two timestamps:
  72.  
  73. -- The decimal part of the second is in unit
  74. Values timestampdiff (1, char (current timestamp-timestamp ('2017-01-01-00.00.00 ')));
  75. -- Seconds
  76. Values timestampdiff (2, char (current timestamp-timestamp ('2017-01-01-00.00.00 ')));
  77. -- Unit
  78. Values timestampdiff (4, char (current timestamp-timestamp ('2017-01-01-00.00.00 ')));
  79. -- Hours
  80. Values timestampdiff (8, char (current timestamp-timestamp ('2017-01-01-00.00.00 ')));
  81. -- Days
  82. Values timestampdiff (16, char (current timestamp-timestamp ('2017-01-01-00.00.00 ')));
  83. -- Weekly
  84. Values timestampdiff (32, char (current timestamp-timestamp ('2017-01-01-00.00.00 ')));
  85. -- Month
  86. Values timestampdiff (64, char (current timestamp-timestamp ('2017-01-01-00.00.00 ')));
  87. -- Quarterly
  88. Values timestampdiff (128, char (current timestamp-timestamp ('2017-01-01-00.00.00 ')));
  89. -- Year
  90. Values timestampdiff (256, char (current timestamp-timestamp ('2017-01-01-00.00.00 ')));

DB2 common table expression usage

Cross-database access to DB2 tables

DB2 tablespace size limit

Deep understanding of DB2 stored procedures

DB2 connection Server Configuration

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.