Click here to Skip to main content
15,178,008 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to iterate all dates over two years from date=Datetime('2015/03/16','17:00', '+00:00') to date1=Datetime('2017/03/17','19:00', '+00:00')

In the code I have given only one date that is 2015/03/16. I want to iterate for two years up to 2017/03/17.
Output should be like this. <sun pisces="" +25:46:52="" +00:59:46=""> <sun pisces="" +25:42:52="" +00:39:46=""> so on....

What I have tried:

pip install flatlib
pip install python-dateutil
from flatlib import const
from flatlib.chart import Chart
from flatlib.datetime import Datetime
from flatlib.geopos import GeoPos

date = Datetime('2015/03/16', '17:00', '+00:00')
pos = GeoPos('38n32', '8w54')
chart = Chart(date, pos)
sun = chart.get(const.SUN)
print(sun)
Output: <sun pisces="" +25:46:52="" +00:59:46="">
Posted
Updated 23-May-21 5:05am
Comments
Richard MacCutchan 23-May-21 11:02am
   
What is the interval value that you are using?
Srinivas G 2021 23-May-21 11:34am
   
Interval value is 1day and 1hr
Richard MacCutchan 23-May-21 11:45am
   
Up down sideways? And your example above is -4 minutes for the first value, and -20 for the second. You really need to provide a better and more detailed description of exactly what you are trying to achieve.
Srinivas G 2021 23-May-21 11:48am
   
Please only provide for 1hr and 1day only.
Richard MacCutchan 23-May-21 12:02pm
   
And that is supposed to be a detailed explanation?
Srinivas G 2021 23-May-21 12:12pm
   
Can you iterate for the following dates:
From
'date=Datetime('2015/03/16','17:00', '+00:00')
to date=Datetime('2017/03/16','19:00', '+00:00') '
Time interval should be 1 day and 1 Hour.

1 solution

Something like this:
Python
import datetime
date = datetime.datetime.now()
for addDays in range(0, 10):
   print(date + datetime.timedelta(days = addDays))
   
Comments
Srinivas G 2021 23-May-21 10:12am
   
Can you apply your code to my actual code.
OriginalGriff 23-May-21 11:03am
   
Yes, I can.

But the important question is: can you?
If I do all the trivial details, you don't learn anything.
Which means next time you have to do it, you have to ask again. And then again the third time.
And that means it takes you considerably longer that it would if you tried for yourself ... Give it a try, it's only two lines of simple Python code that are relevant!
Srinivas G 2021 23-May-21 11:50am
   
Dude I have tried but error is coming. Please apply your code to my code and help me to get the desired output.
OriginalGriff 23-May-21 11:57am
   
What - exactly - have you tried?
What - exactly - error "is coming"?
What have you tried to fix it?
Richard MacCutchan 23-May-21 12:12pm
   
Good luck. :)
OriginalGriff 23-May-21 12:28pm
   
:sigh:
I think I'm going to need it ...
Srinivas G 2021 23-May-21 12:07pm
   
from flatlib import const
from flatlib.chart import Chart
from flatlib.datetime import Datetime
from flatlib.geopos import GeoPos
date = datetime.datetime.now()
pos = GeoPos('38n32', '8w54')
chart = Chart(date, pos)
sun = chart.get(const.SUN)
for addDays in range(0, 10):
print(sun + datetime.timedelta(days = addDays))

Error is coming when trying to apply your code.
OriginalGriff 23-May-21 12:27pm
   
At the risk of repeating myself:
"What - exactly - error "is coming"?
What have you tried to fix it?"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900