bhavul
2/3/2019 - 8:05 PM

Datetime module

# strptime
start_date = datetime.strptime(start_date_str, '%Y-%m-%d')
day_name = datetime_obj.strftime('%A')

Weeks

%a : Sun, Mon, Tue
%A : Sunday, Monday, Tuesday
%w : weekday as number (0 is sunday, 6 is saturday)
%U : week number of year (00, 01, ... 53) - Sunday as start day
%W : week number of year (00, 01, ... 53) - Monday as start day

Days

%d : day of month as zero padded num (01, 02,...31)
%S : day of year as zero padded num (001, 002, ... 366)

Months

%b : Jan, Feb, Mar,..
%B : January, February, March, ...
%m : Month as number (01, 02, ... 12)

Years

%y : year without century (00, 01, ...99)
%Y : year with century (0000, 0001, ... 2013,2014,..9998)

Hours

%H : 24 hour hour (00, 01, 02...23,24)
%I : 12 hour hour (00, 01, .. 12)
%p : AM or PM

Minutes

%M : Minute (00, 01, .... 59)

Seconds

%S : Seconds (00, 01, ... 59)

Timezone name

%z : UTC, EST, IST, CST... (empty if object is naive)

Exceptions

%% : The % character