Home > Archive > Fortran > November 2005 > derived type for dates
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
derived type for dates
|
|
| beliavsky@aol.com 2005-11-18, 7:01 pm |
| When working with dates in Fortran I have found it convenient to define
a derived type with integer members month, day, year. I have changed
jobs in the private sector and cannot use my old code for a date
derived type. Does someone have code for a date derived type they can
share? Useful functionality IMO includes
overloading addition and subtraction (+,-) so that adding/subtracting
an integer n to a date gives another date n days later/before
overloading subtraction (-) so that differencing two dates gives the
number of days between them
overloading the comparison operators (<,>,== etc.) in a sensible way
| |
| Arjen Markus 2005-11-21, 3:58 am |
| One way to make date computations a lot easier is to use Julian date
and time underneath: the algorithms for converting Gregorian dates to
Julian dates and vice versa are easy and you could simply define a
derived type like:
type date
real(kind=kind(1.0d0) :: julian
end type
and then add the functions and operations you need.
(If you fail to find code for these conversions, I can provide some)
Regards,
Arjen
|
|
|
|
|