Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get January 1st of next year

Tags:

python

django

This really shouldn't be this hard but for some reason I can't seem to get it.

I am trying to run a filter on my query that compares the date range between today, and the first day of next year.

Getting today is no problem, but I can't seem to get the first day of next year. I want to be able to provide myself with Jan 1/2013

Here is my filter so far:

cur_il = Investment.objects.all().filter(plan = plan).order_by('financial_institution').filter(maturity_date__range=[now, nextyear])

Obviously I use this to get today's date:

now = datetime.now()

How can I get the next date?

like image 509
TheLifeOfSteve Avatar asked Jan 30 '26 08:01

TheLifeOfSteve


1 Answers

Does this work?

>>> today = datetime.datetime.now()
>>> next_year = datetime.datetime(year=today.year+1, month=1, day=1)
>>> next_year
datetime.datetime(2013, 1, 1, 0, 0)
like image 51
RocketDonkey Avatar answered Feb 01 '26 23:02

RocketDonkey