|
2 | 2 | title: Template functions - date
|
3 | 3 | description: Describes the functions to use in an Azure Resource Manager template (ARM template) to work with dates.
|
4 | 4 | ms.topic: conceptual
|
5 |
| -ms.date: 03/10/2022 |
| 5 | +ms.date: 05/02/2022 |
6 | 6 | ---
|
7 | 7 |
|
8 | 8 | # Date functions for ARM templates
|
@@ -53,6 +53,122 @@ The next example template shows how to set the start time for an Automation sche
|
53 | 53 |
|
54 | 54 | :::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/date/datetimeadd-automation.json":::
|
55 | 55 |
|
| 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 | + |
56 | 172 | ## utcNow
|
57 | 173 |
|
58 | 174 | `utcNow(format)`
|
|
0 commit comments