Versions Compared

Key

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

...

Excerpt
hiddentrue

If we want to create a list of dates such as [19930601, 19930701, ..., 20160701, 20160801], where for each year we have the first day of the same months, the following code snippet will create such a list

How can I create a list of dates for months over several years?

Step-by-step guide

If we want to create a list of dates such as [19930601, 19930701, ..., 20160701, 20160801], where for each year we have the first day of the same months, the following code snippet will create such a list:


Tabs Container
directionhorizontal


Tabs Page
titleMacro


Code Block
languagepy
d1 = 1993-06-01
d2 = 2016-08-01
d = d1
datelist = []
while d <= d2 do
    datelist = datelist & [d]
    d = addmonths(d, 12)
end while
print(datelist)



Tabs Page
titlePython


Code Block
languagepy
import metview as mv
from datetime import datetime

d1 = datetime(1993,6,1)
d2 = datetime(2016,8,1)
d = d1
datelist = []
while d <= d2:
    datelist.append(d)
    d = mv.addmonths(d, 1)

print(datelist)




Content by Label
showLabelsfalse
max5
spaces~usa
showSpacefalse
sortmodified
reversetrue
typepage
cqllabel = "kb-how-to-articlemetview-faqs" and label = "date" and type = "page" and space = "UDOC"
labelskb-how-to-article

...