-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathConvertDateTime.js
More file actions
30 lines (29 loc) · 846 Bytes
/
ConvertDateTime.js
File metadata and controls
30 lines (29 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
Created by: RemcoE33
https://github.com/RemcoE33/apps-script-codebase
*/
/**
* Returns converterd timestamps.
*
* @param {A1:B5} range - Input (multiple column) range.
* @param {"UTC"} timezone - Enter desired timezone.
* @param {"yyyy-MM-dd uu:mm:ss"} format - Enter timestamp formatting.
* @return {array} range of converted timezones.
* @customfunction
*/
function CONVERTDATETIME(range, timezone, format) {
const output = []
if (Array.isArray(range)) {
range.forEach(row => {
const outputRow = []
row.forEach(col => {
outputRow.push(Utilities.formatDate(new Date(col.split("+")[0]), timezone, format))
})
output.push(outputRow);
})
return output
} else {
const timestamp = range.toString()
return Utilities.formatDate(new Date(timestamp.split("+")[0]), timezone, format)
}
}