[program-l] Re: Python: how do I remove the time component from a date?

  • From: Jim Bauer <holdsworthfan@xxxxxx>
  • To: program-l@xxxxxxxxxxxxx
  • Date: Mon, 3 Jan 2022 10:44:00 -0600

Assuming `parser.parse` is from dateutil, the return value will be a datetime 
object with a `date` method.

print(start_date.date())
Output (for me): 2022-01-01


On 1/3/2022 10:16 AM, pranav@xxxxxxxxxxxxxxxxx wrote:
Hi all,

I have the following code which should give me only date but the time
component is still there.

start_date=datetime.date.today().strftime('%Y') + "/01/01"
start_date=parser.parse(start_date)


end_date=datetime.date.today().strftime('%Y/%m/%d')
end_date=parser.parse(end_date)
print(start_date)
print(end_date)
sys.exit()

The output of the above code is:
2022-01-01 00:00:00
2022-01-03 00:00:00

The time component is still there.
Pranav

** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq


** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq

Other related posts: