Search code examples
idl-programming-language

Is IDL able to add / subtract from date?


As you can see the question above, I was wondering if IDL is able to add or subtract days / months / years to a given date.

For example:

given_date = anytim('01-jan-2000')
print, given_date

1-Jan-2000 00:00:00.000

When I would add 2 weeks to the given_date, then this date should appear:

15-Jan-2000 00:00:00.000

I was already looking for a solution for this problem, but I unfortunately couldn't find any solution.

Note: I am using a normal calendar date, not the julian date.


Solution

  • Are you only concerned with dates after 1582? Is accuracy to the second important?

    The ANYTIM routine is not part of the IDL distribution. Possibly there are third party routines to handle time increments, but I don't know of any builtin to the IDL library.

    By default, which you are using, ANYTIM returns seconds from Jan 1, 1979. So to add/subtract some number of days, weeks, or years, you could calculate the number of seconds in the time interval. Of course, this does not take into account leap seconds/years (but leap years are fairly easy to take into account, leap seconds requires a database of when they were added). And adding months is going to require determining which month so to determine the number of days in it.