Date between 2 dates

40 views
Skip to first unread message

grahamsc...@gmail.com

unread,
Jan 15, 2023, 6:33:13 PM1/15/23
to mementodatabase
I have a datbase I designed for holiday bookings and want to calculate the amount of nights stay  between the checkin day and checkout day, how is this done please

Eg
Stay 1
Checkin 12/5/2023     checkout 15/5/23      = 3nights
Stay 2 
checkin 15/5/2023     checkout  18/5/2023    = 3 Nights
Stay 3
Checkin 18/5/2023     checkout 26/5/2023     = 8 nights

Craig Hunter

unread,
Jan 15, 2023, 9:29:06 PM1/15/23
to grahamsc...@gmail.com, mementodatabase
In memento javascript field you can try adding javascript library - "moment"

There's a lot to learn there, but it handles all the edge cases well. Leap years, timezones, ...

If you don't want javascript, a calculation field would be:
(#{d2}-#{d1})/24/3600
where d1 is the checkin date field, and d2 is the check out date field. The division is because dates are stored as seconds after a certain date.

grahamsc...@gmail.com

unread,
Jan 15, 2023, 10:04:44 PM1/15/23
to mementodatabase
thankyou craig much appreciated all good now

Bill Crews

unread,
Jan 16, 2023, 1:29:27 AM1/16/23
to grahamsc...@gmail.com, mementodatabase
In Memento Help, under Calendar, it says this and gives an example...

Craig's that there's a lot to learn, both about moment.js and about data arithmetic in general, but so long as you stay in modern times, the following JavaScript field script will do just what you want...

((field("checkout").getTime() - field("check-in").getTime()) / (1000 * 60 * 60 * 24)).toFixed();

--
You received this message because you are subscribed to the Google Groups "mementodatabase" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mementodataba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mementodatabase/c0fc2db6-9194-433f-bd06-9f8516a4ed0cn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages