Skip to content

Commit 42ece53

Browse files
authored
Merge pull request #196779 from tfitzmac/0502epoch
add epoch time functions
2 parents d321851 + a388e49 commit 42ece53

File tree

2 files changed

+92
-2
lines changed

2 files changed

+92
-2
lines changed

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

Lines changed: 89 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,94 @@ 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.6 or later**.
101+
102+
### Example
103+
104+
The following example shows output values for the epoch time functions.
105+
106+
```bicep
107+
param convertedEpoch int = dateTimeToEpoch(dateTimeAdd(utcNow(), 'P1Y'))
108+
109+
var convertedDatetime = dateTimeFromEpoch(convertedEpoch)
110+
111+
output epochValue int = convertedEpoch
112+
output datetimeValue string = convertedDatetime
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+
## dateTimeToEpoch
123+
124+
`dateTimeToEpoch(dateTime)`
125+
126+
Converts an ISO 8601 datetime string to an epoch time integer value.
127+
128+
Namespace: [sys](bicep-functions.md#namespaces-for-functions).
129+
130+
### Parameters
131+
132+
| Parameter | Required | Type | Description |
133+
|:--- |:--- |:--- |:--- |
134+
| dateTime | Yes | string | The datetime string to convert to an epoch time. |
135+
136+
### Return value
137+
138+
An integer that represents the number of seconds from midnight on January 1, 1970.
139+
140+
### Remarks
141+
142+
This function requires **Bicep version 0.5.6 or later**.
143+
144+
### Examples
145+
146+
The following example shows output values for the epoch time functions.
147+
148+
```bicep
149+
param convertedEpoch int = dateTimeToEpoch(dateTimeAdd(utcNow(), 'P1Y'))
150+
151+
var convertedDatetime = dateTimeFromEpoch(convertedEpoch)
152+
153+
output epochValue int = convertedEpoch
154+
output datetimeValue string = convertedDatetime
155+
```
156+
157+
The output is:
158+
159+
| Name | Type | Value |
160+
| ---- | ---- | ----- |
161+
| datetimeValue | String | 2023-05-02T15:16:13Z |
162+
| epochValue | Int | 1683040573 |
163+
164+
The next example uses the epoch time value to set the expiration for a key in a key vault.
165+
166+
:::code language="bicep" source="~/quickstart-templates/quickstarts/microsoft.storage/storage-blob-encryption-with-cmk/main.bicep":::
167+
80168
## utcNow
81169

82170
`utcNow(format)`

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Bicep functions
33
description: Describes the functions to use in a Bicep file 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
# Bicep functions
@@ -56,6 +56,8 @@ The following functions are available for working with arrays. All of these func
5656
The following functions are available for working with dates. All of these functions are in the `sys` namespace.
5757

5858
* [dateTimeAdd](./bicep-functions-date.md#datetimeadd)
59+
* [dateTimeFromEpoch](./bicep-functions-date.md#datetimefromepoch)
60+
* [dateTimeToEpoch](./bicep-functions-date.md#datetimetoepoch)
5961
* [utcNow](./bicep-functions-date.md#utcnow)
6062

6163
## Deployment value functions

0 commit comments

Comments
 (0)