Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29281 Discussions

Convert some date to seconds since 1970

ipesenson
Beginner
1,169 Views
Hi,
I need to convert different dates into seconds since 1970. There seems to be a plethora of functions to do this to today's date and time, but I need to do this for any date. So I basically need to have an inverse function of GMTIME. It seems like the function RTC would be helpful, but it again only works with current date as far as I can tell. Any hints would be greatly appreciated. Thank you very much.

-ip
0 Kudos
1 Reply
pcurtis
Beginner
1,169 Views
Here are functions you need to convert any date into
a unique integer, which allows easy time interval arithmetic.

FUNCTION julian_date (yyyy, mm, dd) RESULT (julian)
IMPLICIT NONE
! converts calendar date to Julian date
! cf Fliegel & Van Flandern, CACM 11(10):657, 1968
! example: julian_date(1970,1,1)=2440588
INTEGER,INTENT(IN) :: yyyy,mm,dd
INTEGER :: julian
julian = dd-32075+1461*(yyyy+4800+(mm-14)/12)/4 + &
367*(mm-2-((mm-14)/12)*12)/12- &
3*((yyyy + 4900 + (mm - 14)/12)/100)/4
END FUNCTION julian_date


SUBROUTINE get_ymd (jd, yyyy, mm, dd)
IMPLICIT NONE
! expands a Julian date into a calendar date
! cf Fliegel & Van Flandern, CACM 11(10):657, 1968
INTEGER,INTENT(IN) :: jd
INTEGER,INTENT(OUT) :: yyyy,mm,dd
INTEGER :: l,n
l = jd + 68569
n = 4*l/146097
l = l - (146097*n + 3)/4
yyyy = 4000*(l + 1)/1461001
l = l - 1461*yyyy/4 + 31
mm = 80*l/2447
dd = l - 2447*mm/80
l = mm/11
mm = mm + 2 - 12*l
yyyy = 100*(n - 49) + yyyy + l
END SUBROUTINE get_ymd

0 Kudos
Reply