Convert datetime and timedelta from Python to IDL

Question:

Please does anyone know how to convert the following python script to IDL,

hours = list(Timed)
start_date = datetime(year=1800, month=1, day=1, hour=0, minute=0, second=0)
days =[] 
Months =[]
Years =[]   
for hour in hours:
    date = start_date + timedelta(hours=hour)
    Months.append(date.month)
    Years.append(date.year) 

The script converts the data below to day, month, and year starting from 1800:00:00.0

Timed = [1.52887e+06,1.52959e+06,1.53034e+06,1.53108e+06,1.5318e+06,1.53254e+06,1.53326e+06,1.53401e+06,1.53475e+06,1.53542e+06,1.53617e+06,1.53689e+06,1.53763e+06]

I want to rewrite the Python script in IDL.

Asked By: TThoye

||

Answers:

I suggest using CALDAT and JULDAY.
You need to convert Timed to days.

IDL> start_date = julday(1, 1, 1800, 0, 0, 0)
IDL> Timed = [1.52887e+06,1.52959e+06,1.53034e+06,1.53108e+06,1.5318e+06,1.53254e+06,1.53326e+06,1.53401e+06,1.53475e+06,1.53542e+06,1.53617e+06,1.53689e+06,1.53763e+06]
IDL> caldat, start_date + (Timed / 24), month, day, year  ; convert Timed to days and add to start_date
IDL> year                                               
        1974        1974        1974        1974        1974        1974        1974        1975        1975        1975        1975
        1975        1975
IDL> month
           5           6           8           9          10          10          11           1           1           2           4
           5           5
IDL> day
          31          30           1           1           1          31          30           1          31          28           1
           1          31
Answered By: sappjw