In SQL, DATE and TIME are popular functions. You can find in many projects the DATE and Time functions used in SQL Queries.
I have shared top examples of DATE and TIME functions in this post for your quick reference.
DATE SQL Queries
SQL Query to get System Date
You can get system date using sysibm.sysdummy1. Those are current date current time and current time zone you can get fro sysibm.sysdummy1.
Extract Date and Time
You can use extract command to extract date, day, month portion from Timestamp. This extract command you can use in WHERE or ORDER BY clause.
SELECT ORDER_DATE, ORDER_TOTAL
FROM ORDER_TABLE
WHERE EXTRACT(MONTH FROM ORDER_DATE)=9;
SELECT ORDER_TOTAL
FROM ORDER_TABLE
WHERE YEAR(ORDER_DATE)=2000;

SQL TO_CHAR function to convert DATE to CHAR
TO_CHAR(ORDER_DATE,YY-MM-DD)
This function converts the Order date to Char date.
Tricky SQL Last Day of the Month in DB2
SELECT ORDER_DATE,
DATE(SUBSTR
(CHAR(ORDER_DATE),1,8) ||
'01' + 1 MONTH - 1 DAY
AS LAST_DAY_OF_MONTH
FROM ORDER_TABLE;
DB2 Limitation on Calculating TimeStamp Differences
When you calculate differences of Timestamp, it does not consider leaf year. Always DB2 consider, 30 days per month
Differences of DATE and Time
You can find examples to find differences for DATE and TIME for your project, this is my post on it useful for you to refer.
Related Posts