DateSetDay

See Also: Time and Date Functions

Purpose

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:

Return Type

DateTime

Syntax

DateSetDay( {dtVar}, {iDay} )

Where:

Example

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

Using Date instead of DateTime

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.

Notes