Get the current date:
Select Current date from sysibm.sysdummy1;
Values current date;
--Get the current time
Select current time from Sysibm.sysdummy1;
Values current time;
--Get the current timestamp
Select current Timestamp from sysibm.sysdummy1;
Values current timestamp;
--To adjust the current time or current timestamp to gmt/cut, subtract the current time or time stamp from the current timezone register:
Values current time-current timezone;
Values current timestamp-current timezone;
--Get the current year
Values year (current timestamp);
--Get current month
Values month (current timestamp);
--Get the current day
Values Day (current timestamp);
--Get current time
Values hour (current timestamp);
--Get Minutes
Values minute (current timestamp);
--Get seconds
Values second (current timestamp);
--Get milliseconds
Values Microsecond (current timestamp);
--Extract the date and time separately from the timestamp
Values date (current timestamp);
Values Varchar_format (current TIMESTAMP, ' yyyy-mm-dd ');
Values char (current date);
Values time (current timestamp);
--Calculation of execution date and time
Values current date+1 year;
Values current date+3 years+2 months +15 days;
Values current time +5 hours-3 minutes +10 seconds;
--Calculates the number of days between two dates
Values days (current date) – Days (date (' 2010-02-20 '));
--Change time and date to string
Values char (current date);
Values char (current time);
--to convert a string to a date or time value
Values timestamp (' 2010-03-09-22.43.00.000000 ');
Values timestamp (' 2010-03-09 22:44:36 ');
Values date (' 2010-03-09 ');
Values date (' 03/09/2010 ');
Values time (' 22:45:27 ');
Values time (' 22.45.27 ');
--Calculates the difference between two time stamps:
-The number of seconds is divided into units
Values Timestampdiff (1,char (current timestamp-timestamp (' 2010-01-01-00.00.00 '));
--Unit of seconds
Values Timestampdiff (2,char (current timestamp-timestamp (' 2010-01-01-00.00.00 '));
--Divided into units
Values Timestampdiff (4,char (current timestamp-timestamp (' 2010-01-01-00.00.00 '));
--Hour unit
Values Timestampdiff (8,char (current timestamp-timestamp (' 2010-01-01-00.00.00 '));
--Days for units
Values Timestampdiff (16,char (current timestamp-timestamp (' 2010-01-01-00.00.00 '));
--Week unit
Values Timestampdiff (32,char (current timestamp-timestamp (' 2010-01-01-00.00.00 '));
--month unit
Values Timestampdiff (64,char (current timestamp-timestamp (' 2010-01-01-00.00.00 '));
--Quarterly units
Values Timestampdiff (128,char (current timestamp-timestamp (' 2010-01-01-00.00.00 '));
-The year unit
Values Timestampdiff (256,char (current timestamp-timestamp (' 2010-01-01-00.00.00 '));Example:SELECT * from Wx_account where date (opendate) = ' 2012-04-22 ';
DB2 Time function