Use the date() method:
datetime.datetime.now().date()
Answer from ars on Stack OverflowConvert date to datetime in Python - Stack Overflow
How to turn a datetime into just a date?
python - Convert existing datetime array to date - Stack Overflow
Convert Date like "Mar 24, 2021" to Datetime
Videos
You can use datetime.combine(date, time); for the time, you create a datetime.time object initialized to midnight.
from datetime import date
from datetime import datetime
dt = datetime.combine(date.today(), datetime.min.time())
There are several ways, although I do believe the one you mention (and dislike) is the most readable one.
>>> import datetime
>>> t=datetime.date.today()
>>> datetime.datetime.fromordinal(t.toordinal())
datetime.datetime(2009, 12, 20, 0, 0)
>>> datetime.datetime(t.year, t.month, t.day)
datetime.datetime(2009, 12, 20, 0, 0)
>>> datetime.datetime(*t.timetuple()[:-4])
datetime.datetime(2009, 12, 20, 0, 0)
and so forth -- but basically they all hinge on appropriately extracting info from the date object and ploughing it back into the suitable ctor or classfunction for datetime.
Hello everyone, this is what my date column looks like:
| Date |
|---|
| 2023-11-30 23:20:12 |
| 2023-11-29 20:19:46 |
| 2023-11-28 21:33:25 |
| 2023-11-27 15:31:32 |
What I am trying to do it turn the dates in the column into this "2023-11-30" format only. So I am just trying to have the date and the time not be in the column. Can some please show me how to get rid of the time part of in the date column so that I am left with just this format for dates in the date column:
2023-11-30