Calender

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 17

What is Datetime in Python?

Calendar module in Python has the


calendar class that allows the calculations
for various task based on date, month, and
year.
TextCalendar and HTMLCalendar class
in Python allows you to edit the calendar
and use as per your requirement.
 Code Line 1: We begin with “import calendar” which will
import all the classes of this module.
 Code Line 3: c=
calendar.TextCalendar(calendar.SUNDAY)
 Tells the interpreter to create a text calendar. Start of the
month will be Sunday. In Python, you can format the
calendar as you can change the day of the month to begin
with
 Code Line # 4: str= c.formatmonth(2025,1) We are creating
calendar for the year 2025, Month 1 – January
 Code Line # 5: print str will print the output.
change the value from Sunday to
Thursday
It can also print out the Calendar in
HTML format, this feature is helpful for
developer if they want to make any
changes in the look and feel of calendar
HTMLCalender
Loops over the days of a month by using
c.itermonthday (2025,4), it will fetch the
total number of days for that month.
 Zeros in the output mean that the day of the week is in
an overlapping month, which means it does not belong
to that month.
 These zeros appears in output because, in your code you
have mentioned day (Thursday), so when you call
function “c.itermonthdays”, it will start counting days
from Thursday and your Thursday may not start with
date 1st of April it might be 28th or 29th of March, so
when you execute the code it will start counting days
from 28th of march and any days after that till 1st of
April.
These days will be counted as zero and in
the output you will see these zeroes and
same is applicable to the end of the month.
So except date 1-30 all the dates from
previous as well as post month will appear
in the output as zeroes.
You can fetch the data from the local
system, like months or weekdays, etc
• The output over here shows that we have printed out
the months name from the local system. Likewise,
you can also fetch the weekdays name as shown
below
• The output will depend on the local system, suppose
if your local system is some other countries then it
will give the output as per the local settings of that
country. Here we have months so it won’t be a
difference but if it is a week or day, it will certainly
differ.
 Here printed out the months name from the local
system. Likewise, you can also fetch the weekdays
name as shown below
 The output will depend on the local system, suppose if
your local system is some other countries then it will
give the output as per the local settings of that
country. Here we have months so it won’t be a
difference but if it is a week or day, it will certainly
differ.
Fetch the list of the specific day for a whole
year. For example, there is an audit day on
every first Monday of a week. You want to
know the date of first Monday for each
month. You can use this code

You might also like