I'm trying to modify an existing script that has the following date manipulations:
now = system.date.now() end = system.date.midnight(system.date.addDays(now, -system.date.getDayOfMonth(now)+1)) # 1st of this month start = system.date.addMonths(end, -1) # 1 month prior to end
And I need to add code that will allow me to print out each of the day numbers for the entire month between the 'start' date and the 'end' date, along with doing some database manipulations for each date.
There seems to be plenty of sample code out there that shows how I could start with a date and step through the days like I want to do. But I'm having trouble getting it to work with those first three lines above.
For example the following works fine with 'd' set to datetime.datetime.now() as it is below:
"""Script to add days to a time returned by the system""" import datetime from datetime import date, timedelta from time import gmtime now = system.date.now() end = system.date.midnight(system.date.addDays(now, -system.date.getDayOfMonth(now)+1)) # 1st of this month start = system.date.addMonths(end, -1) # 1 month prior to end print now print start print end #get current time d = datetime.datetime.now() #d=start #print date print(d) #get the day of month print(d.strftime("%d")) modified_date = d + timedelta(days=1) print(modified_date.strftime("%d"))
But when I comment out the 'd = datetime.datetime.now() and uncomment the d=start so that I can use the date range from the existing script, I get the following error:
Traceback (most recent call last): File "<input>", line 23, in <module> AttributeError: 'java.util.Date' object has no attribute 'strftime'
Where line 23 is the 'print(d.strftime("%d"))' line.
I'm thinking this is a simple conversion issue between the java.util.Date format to datetime, but I'm not seeing how to make that conversion.
Suggestions and an 'education' on the topic would be appreciated.
Many thanks in advance!