'How to convert this pywintypes.datetime variable into yyyymmdd format?

I have a variable date_var with the contents that look like this when I do a pprint;

[pywintypes.datetime(2022, 3, 23, 0, 0, tzinfo=TimeZoneInfo('GMT Standard Time', True))]

I would like to convert this pywintypes.datetime variable into the format yyyymmdd. The converted output will be 20220323.

I am using python 3.9.



Solution 1:[1]

I will answer my own question.

I discover date_var is datatime type. So, to convert it to yyyymmdd, the code is date_var.strftime('%Y%m%d').

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 FDL