Difference between two dates

116 views
Skip to first unread message

Amundsf

unread,
Mar 14, 2025, 2:33:46 PM3/14/25
to mementodatabase
Hi

Sorry if this a question answered before. I tried to search, but didn't find it. 

I have two dates and need to get number of days. 
I example:
Date 1: January 1
Date 2: January 10

Expected result: 10 days. 

How do I do that? 

Thank you in advance 
Amund 

RG T

unread,
Mar 14, 2025, 2:48:36 PM3/14/25
to Amundsf, mementodatabase
Bonsoir,
J'ai cette base qui calcule l'écart entre deux dates passées, présentes ou futur. Vous pouvez vous en servir telquel soit vous inspirer du script pour obtenir ce que vous désirez.
TRG

--
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 visit https://groups.google.com/d/msgid/mementodatabase/5a2936f8-6c55-4525-8947-3679a5dbcefen%40googlegroups.com.
Calcul écarts 2 dates Copier.mlt2

Graham Wood

unread,
Mar 16, 2025, 6:14:38 PM3/16/25
to mementodatabase
I use this script

// Function to calculate the difference between two dates in days
function calculateDateDifference(startDate, endDate) {
    if (typeof moment === 'undefined') {
        throw new Error('moment.js library is not loaded');
    }

    const start = moment(startDate).startOf('day');
    const end = moment(endDate).startOf('day');
    const duration = end.diff(start, 'days');
    return duration;
}

// Example usage:
var fromDate = field('From Date'); // Replace 'From Date' with your actual field name
var toDate = field('To Date'); // Replace 'To Date' with your actual field name
var dateDifference = ''; // Initialize dateDifference as an empty string

if (fromDate && toDate) {
    dateDifference = calculateDateDifference(fromDate, toDate);
    field('Days', dateDifference); // Replace 'Days Staying' with your actual field name
}

// Output the result
dateDifference ? dateDifference : 'Date difference not calculated';

Amund Stigen Fjeld

unread,
Mar 18, 2025, 2:45:05 PM3/18/25
to Graham Wood, mementodatabase
Thank you verry much both of you 🙂

You received this message because you are subscribed to a topic in the Google Groups "mementodatabase" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mementodatabase/E_0UNkxmg9I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mementodataba...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/mementodatabase/85f8e5a4-ac64-4a53-b1e8-50c724bba757n%40googlegroups.com.

Graham Wood

unread,
Mar 18, 2025, 5:33:55 PM3/18/25
to mementodatabase
Your welcome Amundsf.
I forgot to mention how to use it. You need 3 fields

From Date (date field)
To Date (date field)
Days (JS Field)   place this script in it
Reply all
Reply to author
Forward
0 new messages