Hello,
I am a beginner in python, and have a question..
I need to create a list of all dates between two dates..
Lets say beggining date= 2008-1-15
enddate= 2008-2-20
how do I get a list
dates = [2008-1-15, 2008-1-16,...,2008-2-20] ?
4 35756 bvdet 2,851
Expert Mod 2GB
Hello,
I am a beginner in python, and have a question..
I need to create a list of all dates between two dates..
Lets say beggining date= 2008-1-15
enddate= 2008-2-20
how do I get a list
dates = [2008-1-15, 2008-1-16,...,2008-2-20] ?
The datetime module is useful for this problem. Create a datetime object for the start and end dates. The following determines the number of days: - (end_date+datetime.timedelta(days=1)-start_date).days)
Use that value +1 for a range of days. Each date can be incremented by an integer like this: - start_date+datetime.timedelta(days=i)
The datetime module is useful for this problem. Create a datetime object for the start and end dates. The following determines the number of days: - (end_date+datetime.timedelta(days=1)-start_date).days)
Use that value +1 for a range of days. Each date can be incremented by an integer like this: - start_date+datetime.timedelta(days=i)
Thx for quick reply,
I understand the principle of incrementing days, but how to store each day into list or tuple?
In C I would have something like
DATES=[]
number of days=30
start_date= ...
end_date= ...
while (start_date <= end_date)
{
for(i=0; i<30; i++)
DATES[i]=start_date;
start_date++;
}
I solved it .. It look so simple now.. :)
Thx for the help..
bvdet 2,851
Expert Mod 2GB
I solved it .. It look so simple now.. :)
Thx for the help..
You are welcome. I am glad you were able to solve it. Here's what I came up with: - import datetime
-
-
def date_range(start, end):
-
r = (end+datetime.timedelta(days=1)-start).days
-
return [start+datetime.timedelta(days=i) for i in range(r)]
-
-
start = datetime.date(2007,01,01)
-
end = datetime.date(2008,02,01)
-
dateList = date_range(start, end)
-
print '\n'.join([str(date) for date in dateList])
-
-
>>> 2007-01-01
-
2007-01-02
-
2007-01-03
-
2007-01-04
-
2007-01-05
-
...............
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: PW |
last post by:
<rant>
Sorry guys, but I just have to whinge. Dates in ASP are a total pain in the
butt! I seem to get caught out so many times. I realise its my own fault,
but going from the posts in this...
|
by: Tony |
last post by:
Aloha,
I have a problem that I can't think of a (easy) solution for. I'm
building a web app (asp/access) that will allow people to book a cruise
on a 24 passenger yacht that goes around the...
|
by: jnikle |
last post by:
I have two completely unrelated tables, one for reviews and another for
pay periods. The reviews table has a review date in it, and the pay
periods table is just a list of the beginnings of pay...
|
by: PC Datasheet |
last post by:
An Access user saw my name in a newsgroup and sent me a request for help on
a project. As part of the project, a list of the dates in a month was
needed. For anyone needing a list of dates in a...
|
by: sang |
last post by:
Hi
how to list the inserted dates by week,month and year.
That is how to select the dates by past one week.
similarly the month and year of the particular filed.
Thanks in Advance
Sang
|
by: viniiya |
last post by:
Hi All,
How to Create list of Server/Domains and its User Names from the Network using C#?
I tried with Netuserenum and I got only User Names for server but not Domain users.
Code I used:
...
|
by: Matt Lowrance |
last post by:
I have created an object that has a number of properties, that I am
now trying to simply databind to a form. I am using the data designer
to do it and just dragging and dropping the items onto the...
|
by: Luka Djigas |
last post by:
Hello everyone,
please, I need your help. I'm new to python, so I don't know if this
will seem like a stupid question to some of you ...
I have a need to write to a file (or just print on...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |