Monday, March 23, 2020

Get Date OF Week From Datetime

The following function reture weekday in differe format from a day.  
 
def getWeekDayChar(self,date_time : datetime,rt_type : str ) -> str :

    ''' 
     :param date_time: datetime     
     :param rt_type: 'i' = number, 'l' = long form, 's' = short form     
     :return: week date in spefified format 
    ''' 
  
    week_date_dict : dict = {0: ('Monday','Mon'), 1:('Tuesday','Tus'),2 : ('Wendsday', 'Wed'),
                             3:('Thursday','Thu'), 4: ('Friday','Fri') ,
                             5 :('Saturday','Sat')   ,6:('Sunday','Sun')}

    week_date_num : int = date_time.weekday()

    if rt_type == 'i' :
        return week_date_num
    elif rt_type == 'l' :
        return week_date_dict(week_date_num)(0)
    elif rt_type == 's' :
        return week_date_dict(week_date_num)(1)
    else :
        return None

No comments: