Q.No.1 - Write a program to calculate number of days between two dates.
Sol.-
from datetime import date as dayo
def do(d1,d2):
return(d2-d1).days
d1=dayo(2023,2,10)
d2=dayo(2024,3,10)
print("Number of days between date",do(d1,d2),"days")
Explain :
Step 1: We import date from datetime module as dayo name.
Step 2: We define a function name- do and set parameter name d1, d2
Step 3: return (d2-d1).days - it gives the value return d2-d1 in days.
Step 4: Assign d1 and d2 value with dayo mean that the given value will be treated as date.
Step 5: In print we call function.
OUTPUT:
Number of days between date 394 days