-1

I want to release particles every hour for a month and need an array with a date in this format '2013/05/23;00:00:00:000' (YYYY/MM/DD;hh:mm:SS:sss) that has the following hour in every step. So something like this for a whole month:

x=['2013/05/23;01:00:00:000' '2013/05/23;02:00:00:000' '2013/05/23;03:00:00:000' ...'2013/06/23;01:00:00:000']

Any idea how to loop this? Thanks!

1
  • What did you try? Commented Apr 6, 2018 at 7:41

2 Answers 2

0

Something along the lines

import datetime as dt

dt_start = dt.datetime(2013,5,23,1,0)
dt_end = dt.datetime(2013,5,23,4,0)

date_list = []
while dt_start< dt_end:
  dt_start = dt_start + dt.timedelta(hours=1)
  date_list.append('{:%Y/%m/%d;%H:%M:%S:%f}'.format(dt_start))
Sign up to request clarification or add additional context in comments.

3 Comments

I'd use a generator instead.
@Marcel any idea how to make the %f only three characters instead of 6?
unfortunatelly you'll have to trunkate the string to do that (last line): date_list.append('{:%Y/%m/%d;%H:%M:%S:%f}'.format(dt_start)[:-3])
-1
i = 1
x = []    
while i<=12:
    if i<10:
        str = '2013/05/23;0%d:00:00:000' % i
    else:
        str = '2013/05/23;%d:00:00:000' % i
    x.append(str)
    i=i+1

this is code

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.