[Tutor] Finding numeric day in a year...
Mark Lawrence
breamoreboy at yahoo.co.uk
Sat Jun 28 20:13:28 CEST 2014
On 28/06/2014 18:59, Ken G. wrote:
> I know the correct answer should be 001, but I keep getting 179 which is
> the correct answer for June 28, 2014 (I think). I tried using datecode
> in various places instead of today but I am still getting 179. Currently
> using Ubuntu 12.04.4 and Python 2.7. Thanks for any feedback and suggestion.
>
>
> PROGRAM DISPLAY:
>
> # datefind 03.py
>
> import datetime
>
> datecode = "20140101" # from database on file
>
> month = datecode[4:6]
> day = datecode[6:8]
> year = datecode[0:4]
> datecode = year + "-" + month + "-" + day
> today = datecode
> print today
> print
>
> print "Day of year: ", datetime.date.today().strftime("%j")
datetime.date.today() ? :)
>
> TERMINAL DISPLAY:
>
> 2014-01-01
>
> Day of year: 179
>
> ------------------
> (program exited with code: 0)
> Press return to continue
>
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com
More information about the Tutor
mailing list