Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can i convert from 03MAR23 format to yyyy-mm-dd in python

I wanted to convert from 03FEB23 format to yyyy-mm-dd in python
how can I do it?

Use the below code:

from pyspark.sql.functions import *
df=spark.createDataFrame([["1"]],["id"])
df.select(current_date().alias("current_date"), \
      date_format("03MAR23","yyyy-MMM-dd").alias("yyyy-MMM-dd")).show()

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

from datetime import datetime

date_str = '03FEB23'
date = datetime.strptime(date_str, '%d%b%y')
formatted_date = date.strftime('%Y-%m-%d')
print(formatted_date) # Output: 2023-02-03
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading