Skip to content

Commit 15703dc

Browse files
Merge pull request #263473 from mumian/0117-adddatetime
clarify that the dateTimeAdd function doesn't account for leap years
2 parents f40c711 + 885e1b2 commit 15703dc

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

articles/azure-resource-manager/bicep/bicep-functions-date.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Bicep functions - date
33
description: Describes the functions to use in a Bicep file to work with dates.
44
ms.topic: conceptual
55
ms.custom: devx-track-bicep
6-
ms.date: 11/03/2023
6+
ms.date: 01/17/2024
77
---
88

99
# Date functions for Bicep
@@ -32,14 +32,17 @@ The datetime value that results from adding the duration value to the base value
3232

3333
### Remarks
3434

35-
The dateTimeAdd function takes into account leap years and the number of days in a month when performing date arithmetic. The following example adds one month to January 31:
35+
The `dateTimeAdd` function doesn't take leap years into consideration, and _P1Y_ should be interpreted as _P365D_, while _P1M_ should be interpreted as _P30D_. The following Bicep file shows some examples:
3636

3737
```bicep
38-
output add1MonthOutput string = dateTimeAdd('2023-01-31 00:00:00Z', 'P1M') //2023-03-02T00:00:00Z
39-
output add1MonthLeapOutput string = dateTimeAdd('2024-01-31 00:00:00Z', 'P1M') //2024-03-01T00:00:00Z
38+
output addOneYearNonLeap string = dateTimeAdd('2023-01-01 00:00:00Z', 'P1Y') //2024-01-01T00:00:00Z
39+
output addOneYearLeap string = dateTimeAdd('2024-01-01 00:00:00Z', 'P1Y') //2024-12-31T00:00:00Z
40+
41+
output addOneMonthNonLeap string = dateTimeAdd('2023-02-01 00:00:00Z', 'P1M') //2023-03-03T00:00:00Z
42+
output addOneMonthLeap string = dateTimeAdd('2024-02-01 00:00:00Z', 'P1M') //2023-03-02T00:00:00Z
4043
```
4144

42-
In this example, `dateTimeAdd` returns `2023-03-02T00:00:00Z`, not `2023-02-28T00:00:00Z`. If the base is `2024-01-31 00:00:00Z`, it returns `2024-03-01T00:00:00Z` because 2024 is a leap year.
45+
In the preceding example, considering 2023 as a non-leap year, the outcome of adding one year to the initial day of the year is _2024-01-01T00:00:00Z_. Conversely, adding one year to the starting day of 2024, a leap year, results in _2024-12-31T00:00:00Z_, not _2025-01-01T00:00:00Z_, given that a leap year comprises 366 days instead of 365 days. Furthermore, the distinction between leap and non-leap years becomes apparent when adding one month to the first day of February, leading to varying day-of-the-month results.
4346

4447
### Examples
4548

articles/azure-resource-manager/templates/template-functions-date.md

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Template functions - date
33
description: Describes the functions to use in an Azure Resource Manager template (ARM template) to work with dates.
44
ms.topic: conceptual
55
ms.custom: devx-track-arm-template
6-
ms.date: 10/12/2023
6+
ms.date: 01/17/2024
77
---
88

99
# Date functions for ARM templates
@@ -35,22 +35,35 @@ The datetime value that results from adding the duration value to the base value
3535

3636
### Remarks
3737

38-
The dateTimeAdd function takes into account leap years and the number of days in a month when performing date arithmetic. The following example adds one month to January 31:
38+
The `dateTimeAdd` function doesn't take leap years into consideration, and _P1Y_ should be interpreted as _P365D_, while _P1M_ should be interpreted as _P30D_. The following json shows some examples:
3939

4040
```json
41-
"outputs": {
42-
"add10YearsOutput": {
43-
"type": "string",
44-
"value": "[dateTimeAdd('2023-01-31 00:00:00Z', 'P1M')]" //2023-03-02T00:00:00Z
45-
},
46-
"add1MonthOutput": {
47-
"type": "string",
48-
"value": "[dateTimeAdd('2024-01-31 00:00:00Z', 'P1M')]" //2024-03-01T00:00:00Z
41+
{
42+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
43+
"contentVersion": "1.0.0.0",
44+
"resources": [],
45+
"outputs": {
46+
"addOneYearNonLeap": {
47+
"type": "string",
48+
"value": "[dateTimeAdd('2023-01-01 00:00:00Z', 'P1Y')]" //2024-01-01T00:00:00Z
49+
},
50+
"addOneYearLeap": {
51+
"type": "string",
52+
"value": "[dateTimeAdd('2024-01-01 00:00:00Z', 'P1Y')]" //2024-12-31T00:00:00Z
53+
},
54+
"addOneMonthNonLeap": {
55+
"type": "string",
56+
"value": "[dateTimeAdd('2023-02-01 00:00:00Z', 'P1M')]" //2023-03-03T00:00:00Z
57+
},
58+
"addOneMonthLeap": {
59+
"type": "string",
60+
"value": "[dateTimeAdd('2024-02-01 00:00:00Z', 'P1M')]" //2024-03-02T00:00:00Z
61+
}
4962
}
5063
}
5164
```
5265

53-
In this example, `dateTimeAdd` returns `2023-03-02T00:00:00Z`, not `2023-02-28T00:00:00Z`. If the base is `2024-01-31 00:00:00Z`, it returns `2024-03-01T00:00:00Z` because 2024 is a leap year.
66+
In the preceding example, considering 2023 as a non-leap year, the outcome of adding one year to the initial day of the year is _2024-01-01T00:00:00Z_. Conversely, adding one year to the starting day of 2024, a leap year, results in _2024-12-31T00:00:00Z_, not _2025-01-01T00:00:00Z_, given that a leap year comprises 366 days instead of 365 days. Furthermore, the distinction between leap and non-leap years becomes apparent when adding one month to the first day of February, leading to varying day-of-the-month results.
5467

5568
### Examples
5669

0 commit comments

Comments
 (0)