Author Topic: Calculate days between dates  (Read 12584 times)

secs

  • Newbie
  • Posts: 25
  • I'm a llama!
    • View Profile
Calculate days between dates
« on: April 27, 2016, 09:53:42 AM »
Hi all.

I need to store say todays date in eeprom and then each day the pcl is fired up calculate the number of days between the stored date and the current one. Any suggestions?

I am using a F2424 at the moment soon to be replaced with a Fx2424
« Last Edit: April 27, 2016, 09:55:05 AM by secs »

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:Calculate days between dates
« Reply #1 on: April 27, 2016, 11:14:15 PM »
I suggest that you convert your day/month/year format to a Julian date.  Google this.

I have posted a Julian date conversion algorithm on this site.  Search for "Julian" for this thread.

I trans-coded one of the published alorithms from FORTRAN to TBASIC and the results agree with the online calculator at USNO.

' GenJD - custom function to compute Julian Date.
'  Algoritm agrees with USNO (United States Naval Observatory) online Julian Date Converter
'  at http://aa.usno.navy.mil/data/docs/JulianDate.php
'
' 9/17/2013 is JD 2456553
'
' On entry:
'   I = year 2013
'    J = month 1..12
'    K = day of month
'
' On exit:
'   A holds Julian date
'
A = K-32075+1461*(I+4800+(J-14)/12)/4+367*(J-2-(J-14)/12*12) /12-3*((I+4900+(J-14)/12)/100)/4


Good Luck,

Gary D*ickinson
« Last Edit: April 27, 2016, 11:15:54 PM by garysdickinson »

secs

  • Newbie
  • Posts: 25
  • I'm a llama!
    • View Profile
Re:Calculate days between dates
« Reply #2 on: April 28, 2016, 07:24:43 AM »
Thanks Gary. That will do it :-)
Peter