get weekday as week number in a month

Ian Kelly ian.g.kelly at gmail.com
Thu Nov 8 02:23:07 EST 2012


On Thu, Nov 8, 2012 at 12:09 AM, Nikhil Verma <varma.nikhil22 at gmail.com> wrote:
> What i want to know is if i convert it to
>
> date_object = datetime.strptime(' Friday November 9 2012 11:30PM', '%u %B %d
> %Y %I:%M%p' )
>
> It is giving me ValueError saying u is unsupported directive !

Use '%A' to match 'Friday', not '%u'.  The full list of directives can
be found at:

http://docs.python.org/2/library/time.html#time.strftime

> How can i get weekday as week number ?

Is this what you're looking for?

>>> datetime.strptime('Friday November 9 2012 11:30PM', '%A %B %d %Y %I:%M%p').weekday()
4



More information about the Python-list mailing list