|
|
|
|
|
- Range of dates
- Managing the days and months
- Handling the durations
- Operators available for the days
- Calculating the last day of the month
- Calculating a 90-day end-of-month due date
- Calculating the end of a 30-day period
- Calculations on dates
Day (Property) In french: Jour
The Day property is used to: - Get the day from a Date or DateTime variable, or get the number of days from a Duration variable.
- Change the day in a Date or DateTime variable, or change the number of days in a Duration variable.
- Get the day or the number of days from a Date item (in "Date", "Date and Time" or "Duration" format).
- Change the day or the number of days in a Date item (in "Date", "Date and Time" or "Duration" format).
Remark: The Day property is used to easily change dates (add a day, etc). Reminder: Date items are used to manage: - simple dates: "Year - Month - Day" (YYYYMMDD format).
- dates and times: "Year - Month - Day - Hours - Minutes - Seconds - Milliseconds" (YYYYMMDDHHmmSSCCC format).
- durations: "Number of days - Number of hours - Number of minutes - Number of seconds - Number of milliseconds" (+DHHMMSSCCC format).
// Example on a variable StartDate is Date = "20011225" // Add 5 days to the date StartDate.Day += 5 // Modify the days StartDate.Day = 10
// Example on an item Work.StartDate = "20011225" // Add 5 days to the date Work.StartDate.Day += 5 // Modify the days Work.StartDate.Day = 10
Syntax
Finding out the day in a Date, DateTime or Duration variable Hide the details
<Result> = <Date>.Day
<Result>: Integer Day on 2 digits. <Date>: Date or DateTime Name of the variable of type Date, DateTime or Duration to be used.
Modifying the day in a Date, DateTime or Duration variable Hide the details
<Date>.Day = <New day>
<Date>: Date or DateTime Name of the variable of type Date, DateTime or Duration to be used. <New day>: Integer or character string New day in digits (included between 1 and 31). Replaces the day in the specified date.
Finding out the day in a Date item Hide the details
<Result> = <Data file>.<Item>.Day
<Result>: Integer Day on 2 digits. <Data file>: Character string Name of the data file used. This name was defined in the data model editor or with the File Description type. <Item>: Character string Name of the item used. This name is defined in the data model editor or with the Item Description type.
Modifying the day in a Date item Hide the details
<Data file>.<Item>.Day = <New day>
<Data file>: Character string Name of the data file used. This name was defined in the data model editor or with the File Description type. <Item>: Character string Name of the item used. This name was defined in the data model editor or with the Item Description type. <New day>: Integer or character string New day in digits (included between 1 and 31). Replaces the day in the specified date. Remarks The Date and DateTime types are used to handle dates from 01/01/0001 to 12/31/9999. Managing the days and months Case 1: Direct assignment During a direct assignment (for example, MyDay.Day = n), the day must be included between 1 and 31. A WLanguage error occurs if the specified day is incorrect. The following syntax MyDay.Day = MyDay.Day + 5 may generate an error at runtime. For example, the following lines of code trigger an error: // Code triggering the error MyDate is Date = "20201126" Â // 11/26/2020 MyDate.Day = MyDate.Day + 20 Â // Triggers a WLanguage error because the day is equal to 45 Â // Correct code MyDate is Date = "20201126" Â // 11/26/2020 MyDate.Day += 20
// Code triggering the error MyDate is Date = "20201126"  // 11/26/2020 MyDate1 is Date MyDate1.Day = MyDate.Day + 20  // Triggers a WLanguage error because the day is equal to 45  // Correct code MyDate1 = MyDate  // 11/26/2004 MyDate1.Day += 20
Case 2: Operations on the days When performing operations on the dates, the change of month is automatically managed. Therefore, if the number of days is greater than the number of days in the month, the number of days restarts from 1 and the number of the month is automatically modified. The year is also modified if necessary (month of December for instance). For example: StartDate is Date = "20201226" Â // 12/26/2020 // Add 10 days to the date StartDate.Day +=10 Â Â // StartDate is "20050105"
A duration has no limit: the number of days can exceed 30 or 31 days. Operators available for the days The following arithmetic operators can be used with the Day property: StartDate is Date = "20201126" Â StartDate.Day++ Â Â // Add 1 day to the date StartDate.Day+=5 Â Â // Add 5 days ot the date StartDate.Day-=5 Â Â // Subtract 5 days to the date
Calculating the last day of the month To get the last day of a month, simply assign 31 to the Day property of the date. The last day will be automatically calculated according to the specified month.
StartDate is Date = "20201126"
StartDate.Day = 31
Calculating a 90-day end-of-month due date The Day property can be used to calculate a 90-day end-of-month due date. MyDate is Date = "20201126" Â MyDate.Day += 90 Â MyDate.Day = 31
Calculating the end of a 30-day period A 30-day period corresponds to a one-month period from a given date. The Month and Day properties can be used to easily calculate the end date of a 30-day period.
StartDate is Date = "20201126"
EndDate is Date = StartDate
EndDate.Month++
EndDate.Day--
The date storage format allows you to store dates from 01/01/0001 to 12/31/9999.
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|