So this is probably a dumb question, but I have hit a wall! How do you write into a Date/Time field with the current date in the locale timezone? I have tried the .toLocaleString() method and the console will output everything perfectly, but nothing shows up in the field.
This is what I have.
var rightNow = newDate();
var res = rightNow.toLocaleString();
table.updateRecordAsync(record,{
"Date/Time Submitted To Shipping": res
})
Any help would be greatly appreciated!
Update:
I can get the Date/Time in a Date/Time field by using the .toISOString() method, but the time is 5 hours off.
Best answer by Justin_Barrett
There’s no need to convert the date. Just put it directly into the date field.
A couple other tips:
Use let instead of var
Add “await” before the update so that the update fully completes before the next part of your code, or else you might get unpredictable results.
let rightNow = new Date();
await table.updateRecordAsync(record,{
"Date/Time Submitted To Shipping": rightNow
});
You could also create the date on the fly:
await table.updateRecordAsync(record,{
"Date/Time Submitted To Shipping": new Date()
});
I used the latter option in a test just now, and it worked fine.
Thanks! That definitely simplifies things, but it still returns the ISO standard date/time, not the local date/time. How do I get the current local date/time?
I tried to reconstruct the ISO date/time using the getTimeZoneOffset() method as follows.
Thanks! That definitely simplifies things, but it still returns the ISO standard date/time, not the local date/time. How do I get the current local date/time?
I tried to reconstruct the ISO date/time using the getTimeZoneOffset() method as follows.
Believe it or not the console logs the correct local time in the ISO format, but the date/time field in the table has the GMT time??
My wife just asked “Is it a setting or something?” Keep in my mind she thinks Airtable is something you eat on in the sky. Guess what? I had the GMT setting off in the field settings!!