0

I am getting the date-time from the client like this:

Thu Mar 12 2020 00:00:00 GMT+0530 (India Standard Time) 

I want to convert it into:

2020-03-12 

How can I do that?

milanbalazs
  • 4,811
  • 4
  • 23
  • 45
  • 4
    Does this answer your question? [Python datetime to string without microsecond component](https://stackoverflow.com/questions/7999935/python-datetime-to-string-without-microsecond-component) – Majid joghataey Mar 02 '20 at 07:32
  • 1
    Please post your working code. – Syed Mar 02 '20 at 08:58

1 Answers1

0

I think you are looking for something like this:

import datetime
date_now = datetime.datetime.now().date()
print (str(date_now))

or

print(str(datetime.datetime.now().date().strftime('%Y-%m-%d')))

the output will be:

'2020-03-02'

For more information please look the docs.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
coco18
  • 836
  • 8
  • 18