On 06/28/2014 02:39 PM, Alan Gauld wrote:
On 28/06/14 18:59, Ken G. wrote:
datecode = "20140101" # from database on file
month = datecode[4:6]
day = datecode[6:8]
year = datecode[0:4]
use strptime() to parse dates, its much more reliable.
datecode = year + "-" + month + "-" + day
today = datecode
And use strftime() to format them...
print today
print
print "Day of year: ", datetime.date.today().strftime("%j")
This returns todays date whenever you run it.
It has nothing to do with the dates above.
But if you use strptime() to get the date from your string you should
then be able to use strftime to convert it to julian.
BTW You say you get it from "database on file".
Now if that is a real database such as SQLite you will find functions
there to convert it to julian at source... which is easier than
reading it as a string, parsing it, and then converting it back to a
date again...
HTH
Ah, it is a Python database consisting of year-month-date and past drawn
lotto numbers. I have just noticed that I am missing some twice weekly
drawing. I am checking which one I am missing so far this year. Thanks
to all that helps me
solved the puzzle.
Ken
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor