Social Widget

Responsive Ads Here

Friday, February 7, 2020

Python program to calculate the number of days a person have lived on earth

This is a simple python program to calculate the number of days a person has lived on earth.
This program uses the datetime module in python.



Datetime in python
A date in Python is not a data type of its own, but we can import a module named datetime to work with dates as date objects.



Creating Date Objects
To create a date, we can use the datetime() class (constructor) of the datetime module. The datetime() class requires three parameters to create a date: year, month, day.



With these concepts we can proceed to create our code snippet.

Get today's date.
Create a date object using the birthday, month and year as the arguments.
Find the difference between two objects.
Access the day's value from the result.



No comments:

Post a Comment