Home > Net >  Convert YYYY-MM-DD to Aug 26, 2022
Convert YYYY-MM-DD to Aug 26, 2022

Time:08-26

I have date in the form of YYYY-MM-DD how can i format that date into Aug 26, 2022.

def return_date():
    date_returned = YYYY-MM-DD

return date_returned in form of Aug 26, 2022

CodePudding user response:

Is this what you are trying to accomplish?

import datetime

def return_date(ymd_format):
    year, month, day = ymd_format.split("-")
    return datetime.datetime(int(year), int(month), int(day)).strftime("%b %d, %Y")

print(return_date("2022-08-26")) # prints "Aug 26, 2022"

CodePudding user response:

You can easily understand with this example:

from datetime import datetime
# Get current Date
date = datetime.now()
print("dd-MMM-yyyy:", date.strftime("%b %d, %Y"))

# prints "dd-MMM-yyyy: Aug 26, 2022"

I hope this will help you.

  • Related