subtract date and time

Post your questions and help other users.

Moderator: Martin

Post Reply
houdinix64
Posts: 33
Joined: 08 Mar 2013 12:45

subtract date and time

Post by houdinix64 » 05 Sep 2016 03:05

guys please help me with the script. I need a script that checks how many days remaining from actual date to a particular date. This will help me to monitor my work deadline.

trigger= date and time (set to run once a day)
action=script
action=notification on statusbar

particular date must be in dateformat "yyyy-mm-dd hh:mm:ss"

and the remaining days result must be like this "25d"

example:
(2016-09-05 9:00:00) - (2016-09-29 10:00:00) = 25d

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: subtract date and time

Post by Martin » 05 Sep 2016 19:50

Hi,

Following script could work:

Code: Select all

// get the milliseconds since 1970 from the reference date
date = getDate(2016, 9, 29);

// calculate the difference in milliseconds between the reference date and the current date (morning/midnight)
difference = date - getDate(triggertime, 0, 0, 0);

// format the difference as 24d
text = getDurationString(difference);
You could also add one day to the reference date in case it's required:
date = addDays(getDate(2016, 9, 29));

You can also parse a date from a string if desired:
date = getDate("2016-09-29 10:00:00", "yyyy-MM-dd HH:mm:ss");

Regards,
Martin

Post Reply