Calculation for DateDif

77 views
Skip to first unread message

Randy Flinn

unread,
Dec 1, 2025, 7:11:32 PM (8 days ago) Dec 1
to mementodatabase
Hello,

How do I calculate the difference between the current date and a specific date (i.e., 12/25/25 - Today())?

Thanks,
Randy

Graham Wood

unread,
Dec 1, 2025, 7:36:03 PM (8 days ago) Dec 1
to mementodatabase
I have 2 date fields From Date and To Date then use this in a calculation field
datediff(#{from date},#{to date})

Randy Flinn

unread,
Dec 1, 2025, 7:43:41 PM (8 days ago) Dec 1
to Graham Wood, mementodatabase
I have tried the following with no success

datediff(Now(),12/25/25)



--
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/8e781ad4-ed0b-4340-9e0b-a5608aca0456n%40googlegroups.com.

Graham Wood

unread,
Dec 1, 2025, 8:00:38 PM (8 days ago) Dec 1
to Randy Flinn, mementodatabase
You cou use a JavaScript field with this 

var target = new Date("2025-12-25");
var today = new Date();

// Difference in milliseconds
var diffMs = target.getTime() - today.getTime();

// Convert to days
var diffDays = Math.ceil(diffMs / (1000 * 60 * 60 * 24));

diffDays;

David Gilmore

unread,
Dec 2, 2025, 10:51:36 AM (7 days ago) Dec 2
to mementodatabase
There is an issue with doing it like described above, in that there is no compensation for time zone differences.

Time in a Memento field is kept in milliseconds UTC. Now() will return milliseconds in UTC, converted into local time. For example, in my time zone (Pacific, or UTC-8) comparing the time difference when in the evening to a date early the next day will result in a difference of 0, since both times will be on the same day when converted to UTC. Always compensating for the local time zone prevents this. (BTW - Date only fields in Memento may contain the time of day, even if the time is not being used.)

I use the following Javascript function to calculate the number of days, local time, a given date is from Jan 1, 1970. I will do it for both days, then just subtract those numbers to get the number of days:

function DayNumber(dt) {
// Returns the day number (count of days)
// from Jan 1, 1970. Negative for dates
// before then. DT is a Javascript Date Object
  var curr = dt.getTime();
  var curr = Math.floor(curr/60000);
  curr = curr - dt.getTimezoneOffset();
  curr = Math.floor(curr/1440);
  return curr;
}


Example code to get the number of days from now for another Memento Date field:

var e = entry(); // Get pointer to current Memento entry
var dt = new Date(); // Returns current time and date
var itoday = DayNumber(dt); // Todays day count
var dtcalc = new Date(e.field("DateField")); // Memento field containing the date to compare
var icalc = DayNumber(dtcalc); // Get date day count
var iDiff = icalc - itoday;  // Difference

fsjpap...@gmail.com

unread,
Dec 2, 2025, 12:26:36 PM (7 days ago) Dec 2
to mementodatabase
This works for me,

Calculate how many days till our next truck inspection is due : 


if( #{mvi} > now() , rint((#{mvi} - now())/(60*60*24)),'-' )

Where #{MVI} is date field 

2025-12-02_101751.png

Any suggestions how to get rid of statement "for input string" when past due? It should just display "-"


2025-12-02_102140.png

Dan
2025-12-02_102140.png

Mmm

unread,
Dec 2, 2025, 3:10:11 PM (7 days ago) Dec 2
to mementodatabase
"for input string" появилось в  MDB версии 5.8.0.
Обратитесь в поддержку.

вторник, 2 декабря 2025 г. в 20:26:36 UTC+3, fsjpap...@gmail.com:
Reply all
Reply to author
Forward
0 new messages