I have date strings like this:
'January 11, 2010'
and I need a function that returns the day of the week, like
'mon', or 'monday'
etc. I can't find this anywhere in the Python help. Anyone? Thanks.
use date. weekday() Return the day of the week as an integer, where Monday is 0 and Sunday is 6.
isoweekday() to get a weekday of a given date in Python Use the isoweekday() method to get the day of the week as an integer, where Monday is 1 and Sunday is 7. i.e., To start from the weekday number from 1, we can use isoweekday() in place of weekday() . The output is 1, which is equivalent to Monday as Monday is 1.
Method 2: Using strftime() function. In this method of converting the date of the week, the user needs to call strftime() function which is an in-built function and pass the respected parameters into it, and then in return, the function will give the weekdays of the given date to the user.
You might want to use strptime and strftime
methods from datetime
:
>>> import datetime >>> datetime.datetime.strptime('January 11, 2010', '%B %d, %Y').strftime('%A') 'Monday'
or for 'Mon'
:
>>> datetime.datetime.strptime('January 11, 2010', '%B %d, %Y').strftime('%a') 'Mon'
use date.weekday()
Return the day of the week as an integer, where Monday is 0 and Sunday is 6.
http://docs.python.org/2/library/datetime.html#datetime.date.weekday
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With