You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

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:

    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)
    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)


There is no content with the specified labels



  • No labels