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()
>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