import datetime from calendar import monthrange, month_name def datetime_to_str(datetime_obj, format): ''' :param format: %V = Calendar Week %d/%m%Y :return: ''' if datetime_obj == 'current': datetime_obj = datetime.datetime.now() return datetime_obj.strftime(format) else: return datetime_obj.strftime(format) def get_current_date(): return datetime.datetime.now() def get_current_month_number(): current_date = datetime.datetime.now() return int(current_date.strftime("%m")) def add_days_to_date(datetime_obj,count): return datetime_obj + datetime.timedelta(days= count) def substract_days_to_current_date(count): return datetime.datetime.now() - datetime.timedelta(days= count) def get_count_of_days_for_specific_month(year, month_number): ''' :param year: As Int, ex. 2012 :param month_number: As Int, ex. February == 2 :return: ''' return monthrange(year,month_number)[1] # [0] contains the week day