timetuple : Details about date and time as elements of a tuple.
Today's details as timetuple
from datetime import date
Getting time details along with date
time.struct_time(tm_year=2019, tm_mon=9, tm_mday=16, tm_hour=0,
tm_min=0, tm_sec=0, tm_wday=0, tm_yday=259, tm_isdst=-1)
Output is here
from datetime import datetime
time.struct_time(tm_year=2019, tm_mon=9, tm_mday=17, tm_hour=6,
tm_min=18, tm_sec=26, tm_wday=1, tm_yday=260, tm_isdst=-1)
Using date object
time.struct_time(tm_year=2019, tm_mon=12, tm_mday=31, tm_hour=0,
tm_min=0, tm_sec=0, tm_wday=1, tm_yday=365, tm_isdst=-1)
# Year, Month, date, Hour, Minute , Second, mircosecond
Details about the elements of timetuple
tm_year :Year in YYYY format
time.struct_time(tm_year=2019, tm_mon=12, tm_mday=31, tm_hour=23,
tm_min=59, tm_sec=59, tm_wday=1, tm_yday=365, tm_isdst=-1)
tm_month: Month in two digits
tm_mday :Day of the month
th_hour :Hour of the day in 24 hours format
tm_min :Minutes in 2 digits
tm_sec :Seconds in 2 digits
tm_wday :Weekday in number starting with 0 as Sun,1 as Mon ...
tm_yday :Day of the year starting from 1st Jan as 1 and 365 as 31st Dec ( not leap year)
tm_isdst :Daylight Saving Time as flag. It is greater than 0 if DST is in effect. 0 if DST is not in effect and less than 0 if no information is available.
As we get a tuple we can apply all methods of tuple.
Total Number of elements in output is here ( we will use len())
Value of 2nd element i.e date part of the object. ( first element position is 0 )
Displaying all values by looping.
Output is here
for i in dt.timetuple():
All Date Objects