1.

Write a Program to convert date from yyyy-mm-dd format to dd-mm-yyyy format.

Answer»

We can again USE the re MODULE to convert the DATE string as shown below:

import redef transform_date_format(date): return re.sub(r'(\d{4})-(\d{1,2})-(\d{1,2})', '\\3-\\2-\\1', date)date_input = "2021-08-01"PRINT(transform_date_format(date_input))

You can ALSO use the datetime module as shown below:

from datetime import datetimenew_date = datetime.strptime("2021-08-01", "%Y-%m-%d").strftime("%d:%m:%Y")print(new_data)


Discussion

No Comment Found