I’ve learned that Glide uses Luxon in the Z timezone with ISO8601 format to store Date & Time columns. The Date Picker adds 2-3 extra steps, so I came up with an idea to manually input time using JS columns. It worked on my device, but I’m not sure if it works on other devices in different timezones.
My approach:
- Create a TimeID Math column: Set it as
p1
, which calculates minutes from the date:
hour(date)*60 + minute(date)
- Create a Timezone JS column: Set it as
p2
to get the device’s timezone:
Intl.DateTimeFormat().resolvedOptions().timeZone;
- Create a TimeID to ISO8601 Z column: The JS function that converts
p1
(TimeID) andp2
(Timezone) to ISO8601 format in UTC (Z timezone):
function convertToUTC(p1, p2) {
let today = new Date();
let year = today.getFullYear();
let month = String(today.getMonth() + 1).padStart(2, "0");
let day = String(today.getDate()).padStart(2, "0");
// Convert p1 (time in minutes) to hours and minutes
let hours = Math.floor(p1 / 60);
let minutes = p1 % 60;
// Create UTC Date object
let localTime = new Date(`${year}-${month}-${day}T${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}:00Z`);
// Get timezone offset for p2
let timeZoneOffset = new Date().toLocaleString('en-US', { timeZone: p2 });
let localDate = new Date(timeZoneOffset);
let offset = localDate.getTimezoneOffset();
// Adjust the time for timezone offset
localTime.setMinutes(localTime.getMinutes() - offset);
// Return the ISO8601 formatted time in UTC
return localTime.toISOString();
}
return convertToUTC(p1, p2);
- Use Text to Date to convert the
TimeID to ISO8601 Z
column to get your date.
Result:
- This works for me, as it allows staff to quickly select the TimeID from an enum table.
- You can also extend the TimeID to ISO8601 Z column with a
p3
argument to apply this logic for other date columns.
It’s a quick and easy solution for staff, and it works in my case. I hope it works for other timezones too!