|
|
|
|
|
- Date ranges
- Managing months and years
- Operators available for the months
- Calculating the last day of the month
- Calculating a 90-day end-of-month due date
- Calculating the end of a 30-day period
The Month property is used to: - Retrieve the month from a variable of type Date or DateTime.
- Modify the month of a variable of type Date or DateTime.
- Retrieve the month from a Date item (in "Simple date" or "Date and Time" format).
 Not available. - Modify the month in a Date item (in "Simple Date" or "Date and Time" format).
 Not available.
Remark: The Month property simplifies date shifting operations (adding a month, etc.). Reminder: Date fields can be 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)
// Operations on a Date variable StartDate is Date = "20011212" // Add 1 month to the date StartDate.Month++ // Modify the month StartDate.Month = 5
// Operations on an item Work.StartDate = "20011212" // Add 1 month to the date Work.StartDate.Month++ // Modify the month Work.StartDate.Month = 5
Sintaxis <Result>: Integer Month on 2 digits. <Date>: Date or DateTime Name of the variable of type Date or DateTime to be used. <Date>: Date or DateTime Name of the variable of type Date or DateTime to be used. <New month>: Integer or character string New month expressed in numbers (included between 1 and 12). Replaces the month in the specified date.
Finding out the month in a Date item (in "Simple date" or "Date and Time" format) Ocultar los detalles
<Result> = <Data file>.<Item>.Month
<Result>: Integer Month 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 month in a Date item (in "Simple date" or "Date and Time" format) Ocultar los detalles
<Data file>.<item>.Month = <New month>
<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 month>: Integer or character string New month expressed in numbers (included between 1 and 12). Replaces the month in the specified date. Observaciones Date ranges The Date and DateTime types are used to handle dates from 01/01/0001 to 12/31/9999. Managing months and years Case 1: Direct assignment During a direct assignment (for example, MyWork.MyDate.Month = n), the month must be included between 01 and 12. A WLanguage error occurs if an invalid month is specified. The notation MyWork.MyDate.Month = MyWork.MyDate.Month + 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/11/2020 MyDate.Month = MyDate.Month + 2 // Triggers a WLanguage error because the month is equal to 13 // Correct code MyDate is Date = "20201126" // 11/11/2020 MyDate.Month += 2
// Code triggering the error MyDate is Date = "20201126" // 11/11/2020 MyDate1 is Date MyDate1.Month = MyDate.Month + 2 // Triggers a WLanguage error because the month is equal to 13 // Correct code MyDate1 = MyDate // 11/26/2004 MyDate1.Month += 2
Case 2: Operations on monthsWhen performing operations on the dates, the change of year is automatically managed. Therefore, if the number of months is greater than 12, the year is automatically modified and the number of months restarts from 1. For example: StartDate is Date = "20201226"
StartDate.Month += 5
Operators available for the months The following arithmetic operators can be used with the Month property: StartDate is Date = "20201126" StartDate.Month++ // Add 1 month to the date StartDate.Month += 5 // Add 5 months to the date StartDate.Month -= 5 // Subtract 5 months from 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--
Esta página también está disponible para…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|