我有以下代码:
这是我的代码:
SELECT Datee, StartWeek, DATEADD(DAY, 6, StartWeek) AS EndWeek, (DayNo / 7) + 1 AS WeekNo
FROM t
CROSS APPLY (
SELECT DATEADD(DAY, -CASE DATENAME(WEEKDAY, Datee)
WHEN 'Thursday' THEN 0
WHEN 'Friday' THEN 1
WHEN 'Saturday' THEN 2
WHEN 'Sunday' THEN 3
WHEN 'Monday' THEN 4
WHEN 'Tuesday' THEN 5
WHEN 'Wednesday' THEN 6
END, Datee) AS StartWeek
) AS ca1
CROSS APPLY (
SELECT DATEADD(YEAR, DATEDIFF(YEAR, 0, StartWeek), 0) AS FDOY
) AS ca2
CROSS APPLY (
SELECT DATEDIFF(DAY, FDOY, Datee) - CASE DATENAME(WEEKDAY, FDOY)
WHEN 'Thursday' THEN 0
WHEN 'Friday' THEN 6
WHEN 'Saturday' THEN 5
WHEN 'Sunday' THEN 4
WHEN 'Monday' THEN 3
WHEN 'Tuesday' THEN 2
WHEN 'Wednesday' THEN 1
END AS DayNo
) AS ca3
这就是我得到的:
print (start_timestamp)
start_timestamp_no_iso = datetime.strptime(start_timestamp, "%Y-%m-%dT%H:%M:%S.%f")
我了解这意味着什么,但我不明白为什么会发生。我只是将时间戳从iso格式转换为non iso。有什么问题吗?
答案 0 :(得分:4)
您的格式字符串%Y-%m-%dT%H:%M:%S.%f
是绝对正确的。我敢肯定,您在行尾有line feeds
。尝试
start_timestamp_no_iso = datetime.strptime(start_timestamp.strip(' \t\r\n'), "%Y-%m-%dT%H:%M:%S.%f")