If in fact the database uses the Scalinger calendar to internally represent the dates, read here for more information:
Original Message:
Sent: Tue August 06, 2024 11:06 PM
From: Satid S
Subject: Discrepancy Between Documentation and Internal Date Representation in DB2 for i 7.3
Dear Agostino
There is no discrepancy here. It's a case of the description that does not provide more details that enable understanding.
If you Google the word "Scaliger number", you will see the explanation of a Julian period starts on 1 January 4713 BC (Julian calendar) and lasts for 7980 years. So, it's just a number of days counted from that fixed date in a distant past up to the day the date data value is created. This is therefore used as a reference framework for implementing date data type in DB2.
The word "internal" is meant to convey a meaning that it is implemented under the cover and is generally not meant for user to directly access it for any meaningful way. (There is no reason to because of the explanation above.) It is meaningful to DB2 designers for providing a reference point in creating functions for specifying and manipulating dates for you to use. For example, this is why you can manipulate a DATE column data with + or - sign. This Scaliger number is not specific to IBM i 7.3. It has been used for a long time now - up to the current release 7.5 - and likely will still be used into the future.
>>>> What is the correct way to interpret the results obtained through INTEGER(col_date)? <<<<
You are casting (changing the data type of) the data returned from the column data.
------------------------------
Satid S
Original Message:
Sent: Tue August 06, 2024 09:38 AM
From: Agostino Sclauzero
Subject: Discrepancy Between Documentation and Internal Date Representation in DB2 for i 7.3
I am trying to better understand how DB2 for i version 7.3 internally handles dates.
In the SQL Reference documentation, I found the following passage:
The internal representation of a date is a string of 4 bytes that contains an integer. The integer (called the Scaliger number) represents the date.
However, when I run a query to convert a date to an integer, I get a result that appears to be the concatenation of the year, month, and day in the format YYYYMMDD. For example:
CREATE TABLE test_date (col_date DATE);
INSERT INTO test_date (col_date) VALUES ('2024-08-06');
SELECT INTEGER(col_date) AS date_as_integer FROM test_date;
The result of the query (date_as_integer field) is 20240806, which does not seem to correspond to the concept of a "Scaliger number".
Questions:
Could you clarify how DB2 for i version 7.3 internally represents dates?
What is the correct way to interpret the results obtained through INTEGER(col_date)?
Thanks in advance.
------------------------------
Agostino
------------------------------