See Also: Time and Date Functions
The DateSetDay function returns a new DateTime value that is the original value, dtVar, with the day component changed to iDay.
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.
DateSetDay( {dtVar}, {iDay} )
Where:
{dtVar} is a value of type DateTime
{iDay} is an integer value representing the new day component of the DateTime
Procedure TestDateSetDay
DateTime dtVar
//Get the current local date and time
Move (CurrentDateTime()) to dtVar
Move (DateSetDay(dtVar, 20)) to dtVar
// This will print:
// The day of month of 12/20/2003 4:04:27 PM is: 20
Showln "The day of month of " dtVar " is: " (DateGetDay(dtVar))
End_Procedure
You can take advantage of DataFlex's automatic type conversion and use this function with a Date, rather than DateTime, data type. However, be aware that conversion to a Date type will automatically attempt to adjust invalid dates to valid ones. For example, setting 31 as the day of a month that has fewer than 31 days, will adjust the date to the following month:
Move 04/01/2025 to dVar
Move (DateSetDay(dVar, 31)) to dVar
The code above will result in a date of 05/01/2025, since April only has 30 days, making 04/31/2025 an invalid date.
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.