计算上一周周三的日期

直接上code了

 

def get_wed_date():
"""
This function obtains last Wednesday date
"""

uni_string = lambda month,day: "".join([str(month), str(day)]) if len(day) > 1 else \
"".join([str(month), "0", str(day)])

logging.info("Start to calculate the last Wednesday date\n")
today = datetime.date.today()
logging.info("Today date: {0}\n".format(uni_string(str(today.month), str(today.day))))
weekday = today.weekday()
last_wed = today - datetime.timedelta(days=weekday + 5)
last_last_wed = today - datetime.timedelta(days=weekday + 12)
wed_list = [uni_string(str(last_wed.month), str(last_wed.day)), uni_string(str(last_last_wed.month), str(last_last_wed.day))]
logging.info("Last Wednesday date: {0}\n".format(wed_list[0]))
logging.info("Last Last Wednesday date: {0}\n".format(wed_list[1]))
return wed_list

程序运行打印如下:
计算上一周周三的日期

 


  参考博客:

   https://blog.csdn.net/cxl0406/article/details/118673909

 
上一篇:Python如何根据日期判断周几


下一篇:对Joomla用户模式进行颠覆,除了好用还免费?