简体   繁体   English

Python 中的 SQL DATEPART 周数

[英]SQL DATEPART in Python for number of week

So, the thing is that on DATEPART SQL the week starts on Sunday = 0, in python DATETIME the week starts on Monday = 1.所以,问题是,在 DATEPART SQL 上,一周从星期日 = 0 开始,在 Python DATETIME 中,一周从星期一 = 1 开始。

How can I use this SQL code in python:如何在 python 中使用此 SQL 代码:

DATEPART(dw, date)

This function is not working (as I said, the week starts on Monday, not on Sunday):此功能不起作用(正如我所说,一周从星期一开始,而不是从星期日开始):

solved_atDate.isocalendar()[1]
         

Solved, checking if the year is leap:已解决,检查年份是否为闰年:

x = datetime(2021, 3, 24)
x_week = x.isocalendar()[1] 
if (not(x.year % 4 == 0)):
    x_week += 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM