extract a date from a timestamp

Asked 2 years ago, Updated 2 years ago, 32 views

You can get the date and time of creation of the file in DateTime type by executing the code below.
How do I extract only the date from it?

filectime=os.path.getctime(filepath)
timestamp=datetime.datetime.fromtimestamp(filectime)
# create=?

python python3

2022-09-30 16:06

1 Answers

According to @metropolis' comment, it seems to have been resolved by using the datetime.date method.

datetime.date()
Returns the same year, month, and day date object.
https://docs.python.org/ja/3/library/datetime.html#datetime.datetime.date


2022-09-30 16:06

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.