Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
d1 = 2015-03-11 0912:00

Converting numbers into dates

...

Use this syntax to add another variable, d2, which contains the date and time for 13:00h at 2015-03-13. Print it to check it.

Note that when passing numeric dates such as 20150105 to other modules, such as the MARS Retrieval module, these do not need to be converted into date variables.

Date arithmetic

When dealing with dates, the number 1 represents one day. So the expression d1 + 1 gives a date one day later than day 1. To compute the difference, in days, between two dates, it's simply:

...

  • d1 = d1 + 0.5                               # add 12 hours
  • d1 = d1 + hour(12)                          # hour(12) returns 0.5
  • d1 = d1 + hour(23) + minute(58) + second(0) # 2 minutes to midnight

Compute and print the difference between your two dates, d2 and d1.

Looping through dates

Three examples, to get a feel for it:

Code Block
languagepy
for d = 2015-01-01 to 2015-03-01 do
    print(d)
     ... # each step is 1 day
end for

for d = 2015-01-01 to 2015-03-01 by 2 do
    print(d)
     ... # each step is 2 days
end for

for d = 2015-01-01 to 2015-03-01 by hour(6) do
    print(d)
    ... # each step is 6 hours
end for