I am working on a script were I must work with datetime objects in Python. At some point I have one of those objects and I need to get the day of the week (which is a number value) in a 3-letter format (i.e. Tue, Wed, etc.). Here is a brief sample of the code, in dateMatch.group() all I am doing is getting pieces of a string obtained via regex matching.
from datetime import datetime
day = dateMatch.group(2)
month = dateMatch.group(3)
year = dateMatch.group(4)
hour = dateMatch.group(5)
minute = dateMatch.group(6)
second = dateMatch.group(7)
tweetDate = datetime(int(year), months[month], int(day), int(hour), int(minute), int(second))
From that date time object I get a numerical day value (i.e. 18) and I need to convert it to (i.e. Tue).
Thanks!
http://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior
date, datetime, and time objects all support a
strftime(format)
method, to create a string representing the time under the control of an explicit format string....
%a — Locale’s abbreviated weekday name.
>>> datetime.datetime.now().strftime('%a')
'Wed'
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