{"id":17267,"date":"2021-08-26T10:42:46","date_gmt":"2021-08-26T05:12:46","guid":{"rendered":"https:\/\/python-programs.com\/?p=17267"},"modified":"2021-11-22T18:37:11","modified_gmt":"2021-11-22T13:07:11","slug":"python-program-to-calculate-age-in-days-from-date-of-birth","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-calculate-age-in-days-from-date-of-birth\/","title":{"rendered":"Python Program to Calculate Age in Days from Date of Birth"},"content":{"rendered":"

In the previous article, we have discussed Python Program to Check Strontio Number or Not.<\/a>
\nGiven the Date of Birth and task is to calculate the corresponding age in days.<\/p>\n

datetime module:<\/strong><\/p>\n

The datetime module contains numerous classes that can be used to manipulate date and time in both simple and complex ways.<\/p>\n

In this, the date is formatted as the year month date (YY, MM, DD).<\/p>\n

datetime.today()<\/strong> :<\/strong>The current date\/system date is returned by datetime.today().<\/p>\n

To calculate age from date of birth, subtract the date of birth from the current date.<\/p>\n

timedelta() function in Python:<\/strong><\/p>\n

The Python timedelta() function is part of the datetime library and is commonly used for calculating date differences. It can also be used for date manipulation in Python. It is one of the simplest methods for manipulating dates.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given Date of Birth = (2000, 3, 14)<\/pre>\n

Output:<\/strong><\/p>\n

The age in days and time for the Given DOB =  7823 days, 14:16:13.409557<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given Date of Birth = (1999, 5, 16)<\/pre>\n

Output:<\/strong><\/p>\n

The age in days and time for the Given DOB = 8126 days, 14:14:30.074853<\/pre>\n

Program to Calculate Age in Days from Date of Birth<\/h2>\n

Below are the ways to calculate age in days from the given Date of Birth.<\/p>\n