Skip to content

Commit 56fe525

Browse files
authored
Merge pull request #196838 from tfitzmac/0502epoch2
Add epoch functions for json
2 parents 60679d4 + 44dc046 commit 56fe525

File tree

2 files changed

+120
-2
lines changed

2 files changed

+120
-2
lines changed

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

Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
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
5-
ms.date: 03/10/2022
5+
ms.date: 05/02/2022
66
---
77

88
# Date functions for ARM templates
@@ -53,6 +53,122 @@ The next example template shows how to set the start time for an Automation sche
5353

5454
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/date/datetimeadd-automation.json":::
5555

56+
## dateTimeFromEpoch
57+
58+
`dateTimeFromEpoch(epochTime)`
59+
60+
Converts an epoch time integer value to an ISO 8601 datetime.
61+
62+
In Bicep, use the [dateTimeFromEpoch](../bicep/bicep-functions-date.md#datetimefromepoch) function.
63+
64+
### Parameters
65+
66+
| Parameter | Required | Type | Description |
67+
|:--- |:--- |:--- |:--- |
68+
| epochTime | Yes | int | The epoch time to convert to a datetime string. |
69+
70+
### Return value
71+
72+
An ISO 8601 datetime string.
73+
74+
### Example
75+
76+
The following example shows output values for the epoch time functions.
77+
78+
```json
79+
{
80+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
81+
"contentVersion": "1.0.0.0",
82+
"parameters": {
83+
"convertedEpoch": {
84+
"type": "int",
85+
"defaultValue": "[dateTimeToEpoch(dateTimeAdd(utcNow(), 'P1Y'))]"
86+
}
87+
},
88+
"variables": {
89+
"convertedDatetime": "[dateTimeFromEpoch(parameters('convertedEpoch'))]"
90+
},
91+
"resources": [],
92+
"outputs": {
93+
"epochValue": {
94+
"type": "int",
95+
"value": "[parameters('convertedEpoch')]"
96+
},
97+
"datetimeValue": {
98+
"type": "string",
99+
"value": "[variables('convertedDatetime')]"
100+
}
101+
}
102+
}
103+
```
104+
105+
The output is:
106+
107+
| Name | Type | Value |
108+
| ---- | ---- | ----- |
109+
| datetimeValue | String | 2023-05-02T15:16:13Z |
110+
| epochValue | Int | 1683040573 |
111+
112+
## dateTimeToEpoch
113+
114+
`dateTimeToEpoch(dateTime)`
115+
116+
Converts an ISO 8601 datetime string to an epoch time integer value.
117+
118+
In Bicep, use the [dateTimeToEpoch](../bicep/bicep-functions-date.md#datetimetoepoch) function.
119+
120+
### Parameters
121+
122+
| Parameter | Required | Type | Description |
123+
|:--- |:--- |:--- |:--- |
124+
| dateTime | Yes | string | The datetime string to convert to an epoch time. |
125+
126+
### Return value
127+
128+
An integer that represents the number of seconds from midnight on January 1, 1970.
129+
130+
### Examples
131+
132+
The following example shows output values for the epoch time functions.
133+
134+
```json
135+
{
136+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
137+
"contentVersion": "1.0.0.0",
138+
"parameters": {
139+
"convertedEpoch": {
140+
"type": "int",
141+
"defaultValue": "[dateTimeToEpoch(dateTimeAdd(utcNow(), 'P1Y'))]"
142+
}
143+
},
144+
"variables": {
145+
"convertedDatetime": "[dateTimeFromEpoch(parameters('convertedEpoch'))]"
146+
},
147+
"resources": [],
148+
"outputs": {
149+
"epochValue": {
150+
"type": "int",
151+
"value": "[parameters('convertedEpoch')]"
152+
},
153+
"datetimeValue": {
154+
"type": "string",
155+
"value": "[variables('convertedDatetime')]"
156+
}
157+
}
158+
}
159+
```
160+
161+
The output is:
162+
163+
| Name | Type | Value |
164+
| ---- | ---- | ----- |
165+
| datetimeValue | String | 2023-05-02T15:16:13Z |
166+
| epochValue | Int | 1683040573 |
167+
168+
The next example uses the epoch time value to set the expiration for a key in a key vault.
169+
170+
:::code language="json" source="~/quickstart-templates/quickstarts/microsoft.storage/storage-blob-encryption-with-cmk/azuredeploy.json":::
171+
56172
## utcNow
57173

58174
`utcNow(format)`

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Template functions
33
description: Describes the functions to use in an Azure Resource Manager template (ARM template) to retrieve values, work with strings and numerics, and retrieve deployment information.
44
ms.topic: conceptual
5-
ms.date: 04/12/2022
5+
ms.date: 05/02/2022
66
---
77

88
# ARM template functions
@@ -85,6 +85,8 @@ For Bicep files, use the [coalesce](../bicep/operators-logical.md) logical opera
8585
Resource Manager provides the following functions for working with dates.
8686

8787
* [dateTimeAdd](template-functions-date.md#datetimeadd)
88+
* [dateTimeFromEpoch](template-functions-date.md#datetimefromepoch)
89+
* [dateTimeToEpoch](template-functions-date.md#datetimetoepoch)
8890
* [utcNow](template-functions-date.md#utcnow)
8991

9092
For Bicep files, use the [date](../bicep/bicep-functions-date.md) functions.

0 commit comments

Comments
 (0)