BBS: Inland Empire Archive Date: 04-09-92 (08:07) Number: 108 From: MATT HART Refer#: NONE To: GRAHAM CHATFIELD Recvd: NO Subj: Help with DATE$ Conf: (2) Quik_Bas
GC> What I need is a date calculator to perform a function like this:
GC> Take todays date (April 7/92) which date$ prints as "04-07-1992"
GC> and find the new date if I subtract 20 days from todays date.
GC> IE: DATE$ - number_of_days = previous date
GC> or April 7/92 - 20 = March xx/92
' ADDDATE.BAS Matt Hart
'
' OldDate$ in format MM-DD-YYYY
'
DEFINT A-Z
DECLARE FUNCTION AddDate$(OldDate$,NumDays)
INPUT NumDays
IF NumDays => 0 THEN
PRINT Date$+" +";NumDays;" = ";AddDate$(Date$,NumDays)
ELSE
PRINT Date$+" ";NumDays;" = ";AddDate$(Date$,NumDays)
ENDIF
END
FUNCTION AddDate$(OldDate$,NumDays)
MM = VAL(LEFT$(OldDate$,2))
DD = VAL(MID$(OldDate$,4,2))
YY = VAL(RIGHT$(OldDate$,4))
DD = DD + NumDays
LeapYear = -(YY <> 2000 AND YY MOD 4 = 0)
DO UNTIL DD > 0
SELECT CASE MM
CASE 1
DD = DD + 31
YY = YY - 1
MM = 12
LeapYear = -(YY <> 2000 AND YY MOD 4 = 0)
CASE 2,4,6,8,9,11
DD = DD + 31
MM = MM - 1
CASE 3
DD = DD + 28 + LeapYear
MM = MM - 1
CASE 5,7,10,12
DD = DD + 30
MM = MM - 1
END SELECT
LOOP
DO
SELECT CASE MM
CASE 1,3,5,7,8,10
IF DD > 31 THEN
MM = MM + 1
DD = DD - 31
ELSE
EXIT DO
ENDIF
CASE 2
IF DD > 28+LeapYear THEN
MM = MM + 1
DD = DD - 28 - LeapYear
ELSE
EXIT DO
ENDIF
CASE 4,6,8,9,11
IF DD > 31 THEN
MM = MM + 1
DD = DD - 30
ELSE
EXIT DO
ENDIF
CASE 12
IF DD > 31 THEN
MM = 1
DD = DD - 31
YY = YY + 1
LeapYear = -(YY <> 2000 AND YY MOD 4 = 0)
ELSE
EXIT DO
ENDIF
END SELECT
LOOP
M$ = LTRIM$(RTRIM$(STR$(MM))) : IF MM<10 THEN M$="0"+M$
D$ = LTRIM$(RTRIM$(STR$(DD))) : IF DD<10 THEN D$="0"+D$
Y$ = LTRIM$(RTRIM$(STR$(YY)))
AddDate$ = M$+"-"+D$+"-"+Y$
END FUNCTION
---
* Origin: Midnight Micro! V.32/REL (918)451-3306 (1:170/600)

Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET