I ran into a similar problem a while back. While I still have hope that Airtable will add a date input option for scripts, this is what I’m using so far:
let date = new Date();
if (await input.buttonsAsync("Date to use", ,"Today", "Custom"]) === "Custom") {
let newDate = await input.textAsync("Enter a date: M/D[/yyyy] (Current year implied if not included)")
let year = newDate.slice(-5, -4) === "/" ? "" : "/" + date.getFullYear().toString()
date = new Date(`${newDate}${year}`)
}
If the user won’t ever use the current date, remove the if
wrapper and leave the rest.
I ran into a similar problem a while back. While I still have hope that Airtable will add a date input option for scripts, this is what I’m using so far:
let date = new Date();
if (await input.buttonsAsync("Date to use", ,"Today", "Custom"]) === "Custom") {
let newDate = await input.textAsync("Enter a date: M/D[/yyyy] (Current year implied if not included)")
let year = newDate.slice(-5, -4) === "/" ? "" : "/" + date.getFullYear().toString()
date = new Date(`${newDate}${year}`)
}
If the user won’t ever use the current date, remove the if
wrapper and leave the rest.
Thanks! Glad to know it’s not just me. Sometimes it’s hard to know what’s a feature request and what’s “me being an ignorant newb.”
Thanks again @Justin_Barrett for the “Date Picker” module. This plugs in perfectly to the end of the script when I modified it to use these implications.
It looks like this:
'Start': date, // Now inputs the date selected by the user as defined by the 'date' variable...still looking for time
'End': date, // Now inputs the date selected by the user as defined by the 'date' variable...still looking for time
});
Still looking for final piece to the solution:
How would I go about “tabbing” into the ‘Time’ box in a {Date/Time} field? If I’m using the GUI in the table view once you type the ‘Date’ you can simply use the aTab] key on the QWERTY keyboard to move the cursor into the ‘Time’ box. I’m not sure what script would need added to the updated ‘Start’ and ‘End’ data in this script.
For example: Here are a couple things I’ve tried:
Ex 1:
'Start': date + " 12:00pm", // date works...'+' does not work
'End': date + " 1:00pm" // date works...'+' does not work
});
Ex 2:
'Start': date && " 12:00pm", // date works...'&&' does not work
'End': date && " 1:00pm" // date works...'&&' does not work
});
Ex 3:
'Start': date, " 12:00pm", // date works...additional ',' does not work
'End': date, " 1:00pm" // date works...additional ',' does not work
});
…none of these above examples work. I’m probably missing some syntax thing. Or maybe there’s a way to define the string as a variable before hand and use that. But either way, I’m still not sure how to get the cursor to land in that ‘Time’ box of the {Time/Date} field to update the time property to the default I’d like it to be for each the ‘Start’ and ‘End’ fields.
Thanks again for helping this ol’ novice.
Thanks again @Justin_Barrett for the “Date Picker” module. This plugs in perfectly to the end of the script when I modified it to use these implications.
It looks like this:
'Start': date, // Now inputs the date selected by the user as defined by the 'date' variable...still looking for time
'End': date, // Now inputs the date selected by the user as defined by the 'date' variable...still looking for time
});
Still looking for final piece to the solution:
How would I go about “tabbing” into the ‘Time’ box in a {Date/Time} field? If I’m using the GUI in the table view once you type the ‘Date’ you can simply use the aTab] key on the QWERTY keyboard to move the cursor into the ‘Time’ box. I’m not sure what script would need added to the updated ‘Start’ and ‘End’ data in this script.
For example: Here are a couple things I’ve tried:
Ex 1:
'Start': date + " 12:00pm", // date works...'+' does not work
'End': date + " 1:00pm" // date works...'+' does not work
});
Ex 2:
'Start': date && " 12:00pm", // date works...'&&' does not work
'End': date && " 1:00pm" // date works...'&&' does not work
});
Ex 3:
'Start': date, " 12:00pm", // date works...additional ',' does not work
'End': date, " 1:00pm" // date works...additional ',' does not work
});
…none of these above examples work. I’m probably missing some syntax thing. Or maybe there’s a way to define the string as a variable before hand and use that. But either way, I’m still not sure how to get the cursor to land in that ‘Time’ box of the {Time/Date} field to update the time property to the default I’d like it to be for each the ‘Start’ and ‘End’ fields.
Thanks again for helping this ol’ novice.
While the time entry in the field appears to be a separate space, the data stored internally is a single data item. Once you’ve got the date captured, you’ll need to set the time for that item using the appropriate methods on the date object. Here’s a rundown of the set methods on date objects:
https://www.w3schools.com/js/js_date_methods_set.asp
What I recommend is naming the entered date variable something like startTime
, then making a copy of it named endTime
as follows to :
let endTime = new Date(startTime.getTime());
Now use those set methods on startTime
and endTime
to set the proper times. Using the example you provided above (12pm to 1pm), it would look like this:
startTime.setHours(12);
endTime.setHours(13); // setHours uses a range of 0-23, so 13 is 1 pm
Once that’s done, you can use them to set the field values, and the times should appear correctly.
'Start': startTime,
'End': endTime
While the time entry in the field appears to be a separate space, the data stored internally is a single data item. Once you’ve got the date captured, you’ll need to set the time for that item using the appropriate methods on the date object. Here’s a rundown of the set methods on date objects:
https://www.w3schools.com/js/js_date_methods_set.asp
What I recommend is naming the entered date variable something like startTime
, then making a copy of it named endTime
as follows to :
let endTime = new Date(startTime.getTime());
Now use those set methods on startTime
and endTime
to set the proper times. Using the example you provided above (12pm to 1pm), it would look like this:
startTime.setHours(12);
endTime.setHours(13); // setHours uses a range of 0-23, so 13 is 1 pm
Once that’s done, you can use them to set the field values, and the times should appear correctly.
'Start': startTime,
'End': endTime
:exploding_head: Thank you, thank you, thank you!!!