获取星期几的日期 [英] Getting the date of the first day of the week

查看:83
本文介绍了获取星期几的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在具有日期字段的表中有记录。

I have records in a table which have a date field.

我想查询表,以便返回的记录仅是给定日期的星期日的日期

I would like to query the table so that the records returned are only the Sunday's date of a given week.

如何使用python的 datetime 库来实现这一目标?谢谢。

How could I use python's datetime library to achieve this? Thanks.

推荐答案

要获取一周的开始日期:

To get the beginning date of the week:

datetime.today() - datetime.timedelta(days=datetime.today().isoweekday() % 7)

这篇关于获取星期几的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆