Skip to content

Commit 7f4ae1e

Browse files
committed
add epoch time functions
1 parent d52ed3b commit 7f4ae1e

File tree

1 file changed

+90
-1
lines changed

1 file changed

+90
-1
lines changed

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

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Describes the functions to use in a Bicep file to work with dates.
44
author: mumian
55
ms.author: jgao
66
ms.topic: conceptual
7-
ms.date: 09/30/2021
7+
ms.date: 05/02/2022
88
---
99

1010
# Date functions for Bicep
@@ -77,6 +77,95 @@ resource scheduler 'Microsoft.Automation/automationAccounts/schedules@2015-10-31
7777
}
7878
```
7979

80+
## dateTimeFromEpoch
81+
82+
`dateTimeFromEpoch(epochTime)`
83+
84+
Converts an epoch time integer value to an ISO 8601 datetime.
85+
86+
Namespace: [sys](bicep-functions.md#namespaces-for-functions).
87+
88+
### Parameters
89+
90+
| Parameter | Required | Type | Description |
91+
|:--- |:--- |:--- |:--- |
92+
| epochTime | Yes | int | The epoch time to convert to a datetime string. |
93+
94+
### Return value
95+
96+
An ISO 8601 datetime string.
97+
98+
### Remarks
99+
100+
This function requires **Bicep version 0.5.5 or later**.
101+
102+
### Example
103+
104+
The following example shows output values for the epoch time functions.
105+
106+
```bicep
107+
param convertToEpoch int = dateTimeToEpoch(dateTimeAdd(utcNow(), 'P1Y'))
108+
109+
var convertToDatetime = dateTimeFromEpoch(convertToEpoch)
110+
111+
output epochValue int = convertToEpoch
112+
output datetimeValue string = convertToDatetime
113+
```
114+
115+
The output is:
116+
117+
| Name | Type | Value |
118+
| ---- | ---- | ----- |
119+
| datetimeValue | String | 2023-05-02T15:16:13Z |
120+
| epochValue | Int | 1683040573 |
121+
122+
123+
## dateTimeToEpoch
124+
125+
`dateTimeToEpoch(dateTime)`
126+
127+
Converts an ISO 8601 datetime string to an epoch time integer value.
128+
129+
Namespace: [sys](bicep-functions.md#namespaces-for-functions).
130+
131+
### Parameters
132+
133+
| Parameter | Required | Type | Description |
134+
|:--- |:--- |:--- |:--- |
135+
| dateTime | Yes | string | The datetime string to convert to an epoch time. |
136+
137+
### Return value
138+
139+
An integer that represents the number of seconds from midnight on January 1, 1970.
140+
141+
### Remarks
142+
143+
This function requires **Bicep version 0.5.5 or later**.
144+
145+
### Examples
146+
147+
The following example shows output values for the epoch time functions.
148+
149+
```bicep
150+
param convertToEpoch int = dateTimeToEpoch(dateTimeAdd(utcNow(), 'P1Y'))
151+
152+
var convertToDatetime = dateTimeFromEpoch(convertToEpoch)
153+
154+
output epochValue int = convertToEpoch
155+
output datetimeValue string = convertToDatetime
156+
```
157+
158+
The output is:
159+
160+
| Name | Type | Value |
161+
| ---- | ---- | ----- |
162+
| datetimeValue | String | 2023-05-02T15:16:13Z |
163+
| epochValue | Int | 1683040573 |
164+
165+
The next example uses the epoch time value to set the expiration for a key in a key vault.
166+
167+
:::code language="bicep" source="~/quickstart-templates/quickstarts/microsoft.storage/storage-blob-encryption-with-cmk/main.bicep":::
168+
80169
## utcNow
81170

82171
`utcNow(format)`

0 commit comments

Comments
 (0)