Stores date, time, seconds and milliseconds with this data type.
The following table illustrates the properties used to define the Data Type:
The following table illustrates the conversion done by GeneXus according to the DBMS:
||Native Type (Seconds Precision)
||Native Type (Milliseconds Precision)
|DB2 Universal Database
|DB2 UDB for iSeries
Assignments between Date and DateTime attributes are allowed according to the following rules:
Date = DateTime. The receiving field loses the value corresponding to the time.
DateTime = Date. The receiving field’s time value is 12:00:00 AM (00:00:00 in 24-hour format).
Comparisons between Date and DateTime fields in conditions are not allowed. To compare these two data types, you must convert one into other using assignments. For example, if &DT is a DateTime variable and &D is a Date variable you can use any of the following schemes to be able to compare them.
// Scheme 1, create a temporary DateTime variable and compare
&DT1 = &D //Converts &D to DateTime and its value remains in &DT1
//the time part is 12:00.000 AM
if &DT > &DT1
// Scheme 2, create a temporary Date variable and compare
&D1 = &DT //Converts &DT to Date and its value remains in &D1
//the time part is lost
if &D > &D1
Date and DateTime data types are not equivalent. Programs that expect a Date value cannot be called by programs passing a DateTime value and vice versa, otherwise, an error will occur at specification time.
Indices and Search
It is possible to create indices containing DateTime attributes, either as the only component or as part of the key. They can be either ascending or descending (as long as the DBMS allows it).
As far as the search is concerned, there are two things to consider:
The attribute will always be stored in the same way, regardless of the picture. That is, it will contain two parts, one for the date and one for the time.
It is not possible to search for those that 'have the same date' in a direct way. It will be necessary to implement, for example, the following code:
// Code to search for a DateTime attribute value within a given date.
&dtFrom = ymdhmstot(1995, 10, 28, 0, 0, 0)
&dtTo = ymdhmstot( 1995,10, 29, 0, 0, 0) – 1 // Next day minus 1 second
Where dtAttribute >= &dtFrom
Where dtAttribute <= &dtTo
The following table discusses the possible data type changes of an attribute during the reorganization process.
|Original Data type
||Data type to which it is converted
||Yes4. If val is used.
||Yes. If CtoD function is used.
||Yes. If CtoT function is used.
||Yes. If Str function is used to convert.
||Yes3. If DtoC function is used.
||Yes. If time 12:00:00.00 AM is assumed.
||Yes3. If TtoC function is used with the default values.
||Yes. The time part is lost.
N/A. - Not applied.
Yes. - Conversion is allowed.
No. - Conversion is not allowed. The values are lost.
1 - Character, Varchar and Long Varchar types.
2 - Any numeric data type.
3 - It may happen that the receiving attribute is truncated to the right if it is not large enough.
4 - It may happen that the attribute is truncated to the left if it is not large enough.
- Changes in the picture of the DateTime attribute do not imply database reorganization. This is because the way the attribute is stored is independent of the way of displaying it.
- Changes in the precision may imply a database reorganization.
- Empty values are invariable with respect to the Precision. Even though the minimum value for a Datetime2 in SQL Server is 0001-01-01, in GeneXus the empty and minimum is the same than the one for Datetime: 1753-01-01.
&ExpirationDateTime = DateTime.New(2018,6,5,18,0,0,0)
If &ExpirationDateTime >= DateTime.New(2018,6,5,18,0,0,0)
msg("The date and time is not allowed")
Date data type
Data types list