Timestamp from mm-dd-yy date

I need to find the number of days between a particular date in the past and today. I can use Time.now() to get a timestamp for today, but how do I get a timestamp for some other day? The exact input format doesn’t matter (it could be a string or three integers for m-d-y, whatever). I couldn’t find a library function for this.

I want something ike this Matlab code:

d1 = datenum ('12-Nov-2013') ;  % known date of Type 1
dcur = datenum (date) ;  % Today's date
ddif = dcur - d1 ; % No. of days between two dates

The Time object uses the so called UNIX epoch time which counts the seconds from 1.1.1970 and hence if you want to add one day to Time.now() you’d just add 86400 seconds as this is 246060.
To know the number of days between two dates you just divide the difference by 86400.

To convert an arbitrary date into UNIX epoch time you can use the standard C function mktime()

3 Likes

Ah, once more the great and fabulous @ScruffR to the rescue. I (obviously) did not know about mktime. That’ll do it. Thanks!

2 Likes