I would like to format my date in my dataset to have just the date only. I am not displaying the date anywhere on a web page and the only person who sees that chosen date is the recipient of the triggered email.
The variables on the triggered email are just confirming what the user has input into the form, with the variable on the ‘startDate’ in the page code itself currently being set up as '.toLocaleDateString(‘en-GB’), so that the date on the email is shown as 01/01/01.
However, I would like to be able to edit this date field before the input is saved into my dataset by the use of a beforeInsert hook in a dataset, so when I come to do the email variable I then don’t need to worry about having to change the date in the code still.
I have got this exising hook for beforeInsert data.js in my backend:
export function JoinUsForm_beforeInsert(item, context) {
item.firstName = toUpperFirst(item.firstName);
item.lastName = toUpperFirst(item.lastName);
return item;
}
export function Members_beforeInsert(item, context) {
item.firstName = toUpperFirst(item.firstName);
item.lastName = toUpperFirst(item.lastName);
return item;
}
function toUpperFirst(s) {
return s.charAt(0).toUpperCase() + s.slice(1);
}
What I would like to do is to add a formatDate beforeInsert option to the first dataset too, so that it takes the input from the date picker on my form and then saves it as just the date into the dataset.
Something like this:
export function JoinUsForm_beforeInsert(item, context) {
item.firstName = toUpperFirst(item.firstName);
item.lastName = toUpperFirst(item.lastName);
item.startDate = formatDate(s)(item.startDate);
return item;
}
export function Members_beforeInsert(item, context) {
item.firstName = toUpperFirst(item.firstName);
item.lastName = toUpperFirst(item.lastName);
return item;
}
function toUpperFirst(s) {
return s.charAt(0).toUpperCase() + s.slice(1);
}
function formatDate(s) {
return s.split(' ').splice(0,4).join(' ');
}
However, I have tried it and so far it doesn’t work, it will still show the date as the full date and time unless I keep the email variable as .toLocaleDateString(‘en-GB’) in the page code itself.
Anybody know a way to do this as I have only seen so far in the code forum, how to format dates when you are displaying the result on a page.