'How do I convert numpy.datetime64('2022-04-20T00:00:00.000000000') to datetime.date(2022, 4, 04)

I have a column df['Date] which is a datetime64[ns] type and after doing the

sheets= sorted(df['Date'].unique(), reverse =True)

I get a numpy.datetime64('2022-04-20T00:00:00.000000000') format, but I want it to be of this format datetime.date(2022, 2, 16).



Solution 1:[1]

try to use something like this :

test = datetime.datetime.strptime("2022-04-20T00:00:00.000Z","%Y-%m-%dT%H:%M:%S.%fZ")
new_format = "%Y-%m-%d"
test.strftime(new_format)

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 DataSciRookie