%V not related to %Y when using strftime on a datetime object?
Hi, Could you please check this out, I think there's a mistake here. When using datetime.strptime("01/01/2021", "%m/%d/%Y").strftime("%Y.%V"), I get 2021.53 back, although it should be 2020.53, if I understand correctly? Because otherwise we get the last week of the new year, although the date should belong to the last week of the previous year? Thanks, Vanesa
On Thu, Aug 1, 2024 at 2:18 PM Vanesa Močilnik <vanesa.mocilnik@gmail.com> wrote:
Could you please check this out, I think there's a mistake here. When using datetime.strptime("01/01/2021", "%m/%d/%Y").strftime("%Y.%V"), I get 2021.53 back, although it should be 2020.53, if I understand correctly? Because otherwise we get the last week of the new year, although the date should belong to the last week of the previous year?
Please see note 8 at https://docs.python.org/3/library/datetime.html#technical-detail and the second table in https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format... for ISO-related format codes. Instead of %Y in your strftime format, use %G:
datetime.datetime(2021, 1, 1).strftime('%G-%V') '2020-53'
Hope this helps, Zach
participants (2)
-
Vanesa Močilnik
-
Zachary Ware