How do I change the datetime type to the datetime type?

Asked 2 years ago, Updated 2 years ago, 149 views

I want to replace the datetime.datetime object with the datetime.time object.

For example, datetime.datetime Leave only year-month-day in datetime.datetime.now().

What should I do?

python datetime

2022-09-22 22:24

1 Answers

Write datetime.datetime.date(). Returns the datetime.date object that stores the same year, month, and day as datetime.datetime.

Usually

mydatetime = datetime.datetime.now()
mydate = mydatetime.date()

#If you shorten it,
mydate = datetime.datetime.now().date()

However, if you only want to find out today's date, you can use the datetime object without it datetime.date.today() I don't mind just using it.


2022-09-22 22:24

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.