Stores date, time, seconds, and milliseconds values.
The following table illustrates the properties used to define the Data Type:
Generators: .NET, .NET Framework, Java, Apple, Android
The following table illustrates the conversion done by GeneXus according to the DBMS:
DBMS |
Native Type (Seconds Precision) |
Native Type (Milliseconds Precision) |
Oracle |
Date |
TimeStamp |
DB2 Universal Database |
Timestamp |
Timestamp |
Informix |
DateTime |
DateTime(3) |
SQL Server |
DateTime |
DateTime2 |
DB2 UDB for iSeries |
Timestamp |
Timestamp |
PostgreSQL |
Timestamp |
Timestamp |
SAP Hana |
SecondDate |
TimeStamp |
MySQL |
DateTime |
Datetime(3) |
The DateTime data type has two static methods available only for the .NET, .NET Framework, and Java generators.
Generates DateTime instances with specific values for date and time.
DateTime.New(Year,Month,Day, [Hour],[Minute],[Second],[Millisecond])
&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")
EndIf
Now
Obtains the current system date and time.
DateTime.Now()
&datetime = Datetime.Now()
&dateString = &datetime.ToString()
msg(&dateString) // 09/12/23 12:35 PM
Equivalencies Between Date and DateTime
Assignments
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
Comparisons between Date and DateTime fields in conditions are not allowed. To compare these two data types, you must convert one into the 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 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
…
endif
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
…
endif
Parameter Passing
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.
Indexes and Search
It is possible to create indexes containing DateTime attributes as the only component or as part of the key. They can be ascending or descending (as long as the DBMS allows it).
As far as the search is concerned, consider that 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
For each
Where dtAttribute >= &dtFrom
Where dtAttribute <= &dtTo
…
EndFor
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 |
|
Char1 |
Numeric2 |
Date |
Datetime |
Char1 |
N/A |
Yes4, if val is used. |
Yes, if CtoD function is used. |
Yes, if CtoT function is used. |
Numeric2 |
Yes, if Str function is used. |
N/A |
N/A |
N/A |
Date |
Yes3, if DtoC function is used. |
N/A |
N/A |
Yes, if time 12:00:00.00 AM is assumed. |
DateTime |
Yes3, if TtoC function is used with the default values. |
No |
Yes. The time part is lost. |
N/A |
N/A. - Not applicable.
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 - The receiving attribute may be truncated to the right if it is not large enough.
4 - The attribute may be 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 how it is displayed.
- Changes in precision may imply a database reorganization.
- Empty values are invariable with respect to Precision. Even though the minimum value for a Datetime2 in SQL Server is 0001-01-01, in GeneXus empty and minimum are the same as the one for Datetime: 1753-01-01.
When generating iOS code, controls based on the Date / DateTime data type use the Date format property and Hour format property to infer the native styles dateStyle and timeStyle that take into account the user's preferences in the device settings.
Date data type
Data types list