Day from date

62 views
Skip to first unread message

Simon Hall

unread,
Nov 12, 2024, 10:57:39 AM (9 days ago) Nov 12
to mementodatabase
A while back one of you kind people gave me the following script to calculate the day of the week from the date;

let dy = new Date(field('date'));

if (dy.getFullYear() >= 1800) {

moment(field('Date')).format('dddd');

} else {

null;

}

This works perfectly if the date is present and valid.
I am now using it in a different library where the date field (quite correctly) is sometimes empty.
This produces an 'Invalid Date' entry in the Day field.
I would prefer it to just leave the Day field empty also.
Could somebody please suggest an amendment to the above to achieve this please
Thanks

David Gilmore

unread,
Nov 12, 2024, 11:05:59 AM (9 days ago) Nov 12
to mementodatabase
Try this:

if (field("Date") != null) {

  moment(field("Date")).format("dddd");
}

David Gilmore

unread,
Nov 12, 2024, 11:07:32 AM (9 days ago) Nov 12
to mementodatabase
Oops, you need to set that string moment created somewhere:


if (field("Date") != null) {
  let datestr = moment(field("Date")).format("dddd");

Mmm

unread,
Nov 12, 2024, 11:59:37 AM (9 days ago) Nov 12
to mementodatabase
Можно проверить через moment.isDate():

if (moment.isDate(field("date"))) {

    moment(field("date")).format('dddd');

} else {
    null;
}

вторник, 12 ноября 2024 г. в 19:07:32 UTC+3, aa6...@gmail.com:

Simon Hall

unread,
Nov 13, 2024, 12:35:05 AM (8 days ago) Nov 13
to mementodatabase
Perfect. Thanks again.to you all!
Reply all
Reply to author
Forward
0 new messages