See Also: Time and Date Functions
The DateSetMonth function returns a new DateTime value that is the original value, dtVar, with the month component changed to iMonth.
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() or IsNullDateTime() to test if variable is valid.
DateSetMonth( {dtVar}, {iMonth} )
Where:
{dtVar} is a value of type DateTime
{iMonth} is an integer value representing the new Month component of the DateTime
Procedure testDateSetMonth
DateTime dtVar
//Get the current local date and time
Move (CurrentDateTime()) To dtVar
Move (DateSetMonth(dtVar, 4)) To dtVar
// This will print:
// The Month of 4/23/2005 9:15:15 AM is: 4
Showln "The Month of " dtVar " is: " (DateGetMonth(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.