Random Date Formatting Function

  • Share this:

Code introduction


This function accepts a date and a format string, and then returns the date formatted in a randomly chosen format.


Technology Stack : Arrow library

Code Type : Function

Code Difficulty : Intermediate


                
                    
import random
from arrow import arrow

def randomize_time_format(date, format):
    """
    This function takes a date and a time format, and returns the date in a random format.
    """
    formats = ['YYYY-MM-DD', 'DD/MM/YYYY', 'MM-DD-YYYY', 'YYYY/MM/DD', 'DD-MM-YYYY', 'MM/DD/YYYY']
    random_format = random.choice(formats)
    return date.format(random_format)                
              
Tags: