Search This Blog

Saturday, 20 November 2021

Write a Python program to calculate number of days between two dates.

INTRODUCTION

The function returns date object with same year, month and day. All arguments are required. Arguments may be integers, in the following ranges:

  • MINYEAR <= year <= MAXYEAR
  • 1 <= month <= 12
  • 1 <= day <= number of days in the given month and year

If an argument outside those ranges is given, ValueError is raised.

  • Note: The smallest year number allowed in a date or datetime object. MINYEAR is 1.
  • The largest year number allowed in a date or datetime object. MAXYEAR is 9999.
PROGRAM
----------------------------------------------
from datetime import date
f_date = date(2014, 7, 2)
l_date = date(2014, 7, 11)
delta = l_date - f_date
print(delta.days)  
----------------------------------------------
Output:
9

No comments:

Post a Comment

Sentiment Analyzer using NLP and Python - Practical Guide How to - Ai dev Surya

Unlocking Insights: NLP Project for Sentiment Analysis Natural Language Processing (NLP) is revolutionizing how computers understan...