' QBasic program to find the number of days between two given dates DECLARE FUNCTION CountLeapYears% (year AS INTEGER, month AS INTEGER) DECLARE FUNCTION GetDifference% (dt1 AS STRING, dt2 AS STRING) DIM SHARED monthDays(1 TO 12) AS INTEGER ' Initialize the number of days in each month monthDays(1) = 31 monthDays(2) = 28 monthDays(3) = 31 monthDays(4) = 30 monthDays(5) = 31 monthDays(6) = 30 monthDays(7) = 31 monthDays(8) = 31 monthDays(9) = 30 monthDays(10) = 31 monthDays(11) = 30 monthDays(12) = 31 ' Driver code DIM dt1 AS STRING DIM dt2 AS STRING dt1 = "23/03/1956" ' First date as "DD/MM/YYYY" dt2 = "22/01/2025" ' Second date as "DD/MM/YYYY" ' Function call PRINT "Difference between two dates is "; GetDifference(dt1, dt2) END ' Function to count the number of leap years before the given date FUNCTION CountLeapYears% (year AS INTEGER, month AS INTEGER) DIM years AS INTEGER years = year ' Check if the current year needs to be considered for the count of leap years IF month <= 2 THEN years = years - 1 END IF ' Calculate leap years CountLeapYears = years \ 4 - years \ 100 + years \ 400 END FUNCTION ' Function to return number of days between two given dates FUNCTION GetDifference% (dt1 AS STRING, dt2 AS STRING) DIM d1(1 TO 3) AS INTEGER ' Day, Month, Year for dt1 DIM d2(1 TO 3) AS INTEGER ' Day, Month, Year for dt2 DIM n1 AS LONG DIM n2 AS LONG DIM i AS INTEGER ' Parse the input date strings into day, month, year d1(1) = VAL(LEFT$(dt1, 2)) ' Day of first date d1(2) = VAL(MID$(dt1, 4, 2)) ' Month of first date d1(3) = VAL(RIGHT$(dt1, 4)) ' Year of first date d2(1) = VAL(LEFT$(dt2, 2)) ' Day of second date d2(2) = VAL(MID$(dt2, 4, 2)) ' Month of second date d2(3) = VAL(RIGHT$(dt2, 4)) ' Year of second date ' Count total number of days before dt1 n1 = d1(3) * 365& + d1(1) ' Add days for months in given date FOR i = 1 TO d1(2) - 1 n1 = n1 + monthDays(i) NEXT i ' Add a day for every leap year n1 = n1 + CountLeapYears(d1(3), d1(2)) ' Count total number of days before dt2 n2 = d2(3) * 365& + d2(1) ' Add days for months in given date FOR i = 1 TO d2(2) - 1 n2 = n2 + monthDays(i) NEXT i ' Add a day for every leap year n2 = n2 + CountLeapYears(d2(3), d2(2)) ' Return difference between two counts GetDifference = n2 - n1 END FUNCTION