Pythondex
Python Programs

Python Program To Calculate Seconds In Year Month Week And Day

Last updated May 1, 2023 by Jarvis Silva

Want to know how to create a python program to calculate seconds in a year, month, week and day. Then you are at the right place, today in this tutorial we will see you how can we use python to calculate seconds in every date format .

As we have to calculate 4 types of dates so we will have to create a seperate python program for each one below are all the programs we will create:

  • Python program to calculate number of seconds in a year.
  • Python program to calculate number of seconds in a month.
  • Python Program to calculate number of seconds in a week.
  • Python program to calculate number of seconds in a day.

So now let’s see how to create all the program one by one.

Python program to calculate number of seconds in a year


#Python program to print the Number of seconds in Year

days_in_year = 365
hours_in_day = 24
minutes_in_hour = 60
seconds_in_minute = 60

result = days_in_year * hours_in_day * minutes_in_hour * seconds_in_minute

print(f"Number of seconds in a year are: {result}")

Above is the code to calculate the number of seconds in a year using python, In this program we multiply seconds in a minute by minutes in an hour by hours in a day by days in a year, which gives us the number of seconds in a year.

Output


Number of seconds in a year are: 31536000

Python program to calculate number of seconds in a month.


#Python program to print the Number of seconds in month

days_in_month = 31 
hours_in_day = 24
minutes_in_hour = 60
seconds_in_minute = 60

result = days_in_month * hours_in_day * minutes_in_hour * seconds_in_minute

print(f"Number of seconds in a month are: {result}")

Above is the code to calculate seconds in a month using python, In this program we multiply seconds in a minute by minutes in an hour by hours in a day by days in a month, which gives us the number of seconds in a month.

Output


Number of seconds in a month are: 2678400

Python program to calculate number of seconds in a week.


#Python program to print the Number of seconds in week

days_in_week = 7
hours_in_day = 24
minutes_in_hour = 60
seconds_in_minute = 60

result = days_in_week * hours_in_day * minutes_in_hour * seconds_in_minute

print(f"Number of seconds in a week are: {result}")

Above is the code to calculate seconds in a week using python, In this program we multiply seconds in a minute by minutes in an hour by hours in a day by days in a week, which gives us the number of seconds in a week.

Output


Number of seconds in a week are: 604800

Python program to calculate number of seconds in a day.


#Python program to print the Number of seconds in day

hours_in_day = 24
minutes_in_hour = 60
seconds_in_minute = 60

result = hours_in_day * minutes_in_hour * seconds_in_minute

print(f"Number of seconds in a day are: {result}")

Above is the code to calculate the number of seconds in a day using python. In this program we multiply seconds in a minute by minutes in an hour by hours in a day, which gives us the number of seconds in a day.

Output


Number of seconds in a day are: 86400

Combination Of All Programs In One Program


# Python program to print the Number of seconds in all

days_in_year = 365
days_in_month = 31
days_in_week = 7
hours_in_day = 24
minutes_in_hour = 60
seconds_in_minute = 60

seconds_in_year = days_in_year * hours_in_day * minutes_in_hour * seconds_in_minute
seconds_in_month = days_in_month * hours_in_day * minutes_in_hour * seconds_in_minute
seconds_in_week = days_in_week * hours_in_day * minutes_in_hour * seconds_in_minute
seconds_in_day = hours_in_day * minutes_in_hour * seconds_in_minute

print(f"Number of seconds in a year are: {seconds_in_year}")
print(f"Number of seconds in a month are: {seconds_in_month}")
print(f"Number of seconds in a week are: {seconds_in_week}")
print(f"Number of seconds in a day are: {seconds_in_day}")

Above program is made by combining all 4 programs, this program will print the number of seconds in year, month, week and day.

Output


Number of seconds in a year are: 31536000
Number of seconds in a month are: 2678400
Number of seconds in a week are: 604800
Number of seconds in a day are: 86400

How to run these programs?

To run this program you can run it on your computer if you have python installed or you can use an online python compiler to run each program.

If you want to install python on your computer, then you can refer to this guide: Install and setup python on your computer.

Summary

These were all the python programs to calculate the number of seconds in a year, month, week and a day. I hope you found this guide helpful and useful. Do share it with your friends who might be interested.

Here are some more python programs for you:

I hope you found what you were looking for from this tutorial. If you want more python tutorials like this, do join our Telegram channel for future updates.

Thanks for reading, have a nice day 🙂