See Also: Time and Date Functions
The DateSetYear function returns a new DateTime value that is the original value, dtVar, with the year component changed to iYear.
We recommend using the newer, higher level DateSet function to set a date and the DateAddXXX (DateAddDay, DateAddHour, DateAddMillisecond, DateAddMinute, DateAddMonth, DateAddSecond, DateAddYear) functions to manipulate DateTimes/Dates and the DateGetXXX (DateGetDay, DateGetHour, DateGetMillisecond, DateGetMinute, DateGetMonth, DateGetSecond, DateGetYear) functions to retrieve DateTimes/Dates.
The DateSetXXX (DateSetDay, DateSetHour, DateSetMillisecond, DateSetMinute, DateSetMonth, DateSetSecond, DateSetYear) functions have the following limitations:
Invalid values are allowed in all DateTime parts.
Negative values are wrapped.
Date return type may return error (if out of its range).
Use IsDateValid(), IsNullDateTime() and IsTimeSpanValid() to test if variable is valid.
DateSetYear( {dtVar}, {iYear} )
Where:
{dtVar} is a value of type DateTime
{iYear} is an integer value representing the new year component of the DateTime.
Procedure testDateSetYear
DateTime dtVar
//Get the current local date and time
Move (CurrentDateTime()) To dtVar
Move (DateSetYear(dtVar, 2000)) To dtVar
// This will print:
// The year of 2/23/2000 9:20:09 AM is: 2000
Showln "The year of " dtVar " is: " (DateGetYear(dtVar))
End_Procedure
The DateTime data type can hold invalid DateTime values, such as 02/31/2025. However, when a valid DateTime is required, such as with DateTime arithmetic, error 4523 "The specified DateTime contains an invalid value" will be raised and the result will be a Null DateTime/TimeSpan.
The DateTime data type uses the Windows Regional Settings for the date and time format when converting to/from string. The time format specified in the Windows Regional Settings do not support milliseconds. So, for the DateTime type the format for milliseconds is expected to be in fractions of seconds, using the decimal specifier. For example 1/15/2007 3:03:10.545, where it's 10 seconds and 545 milliseconds, expressed in fractions as 10.545 seconds. Trailing zeroes are normally stripped in a manner consistent with fractional parts, so 10.54 seconds is naturally the same as 10.540 seconds.
The DateTime data type can hold invalid DateTime values. Conversion to/from string can be performed on invalid DateTime values without changing the value. For example, Move "11/31/2006" to dtValue is OK. However, when a valid DateTime is required, such as with DateTime arithmetic, error 4523 "The specified DateTime contains an invalid value" will be raised and the result will be a Null DateTime/TimeSpan.