Statistics: Posted by Antoni — Fri Jul 01, 2005 6:53 pm
Statistics: Posted by moneo — Fri Jul 01, 2005 6:12 pm
Code:
ZTEMP$="1"+Z$+"1"IF LEN(Z$)<>8 OR MID$(STR$(VAL(ZTEMP$)),2)<>ZTEMP$ THEN :RETURN
Statistics: Posted by moneo — Fri Jul 01, 2005 5:51 pm
Code:
ZTEMP$="1"+Z$+"1"IF LEN(Z$)<>8 OR MID$(STR$(VAL(ZTEMP$)),2)<>ZTEMP$ THEN :RETURN
Statistics: Posted by Antoni — Fri Jul 01, 2005 8:57 am
Code:
FUNCTION DayName$ (Y%, M%, D%) IF M% > 2 THEN P% = M% - 3 Q% = Y% ELSE P% = M% + 9 Q% = Y% - 1 END IF Z% = (D% + Q% + Q% \ 4 - Q% \ 100 + Q% \ 400 + CINT(2.6 * P%)) MOD 7 DayName$ = MID$("Tue Wed Thu Fri Sat Sun Mon" , 4 * Z% + 1, 3) END FUNCTION
Code:
IF M% > 2 THEN P% = M% - 3 Q% = Y% ELSE P% = M% + 9 Q% = Y% - 1 END IF
Code:
month p% 2.6*p% cint(2.6*p%) differnce last month april 1 2.6 3 3 march 31 daysmay 2 5.2 5 2 april 30 daysjune 3 7.8 8 3 may 31 daysjuly 4 10.4 10 2 june 30 daysaugust 5 13 13 3 july 31 dayssept 6 15.6 16 3 aug 31 daysoct 7 18.2 18 2 sept 30 daysnov 8 20.8 21 3 oct 31 daysdec 9 23.4 23 2 nov 30 daysjan 10 26 26 3 dec 31 daysfeb 11 28.6 29 3 jan 31 days
Statistics: Posted by Guest — Fri Jul 01, 2005 6:28 am
Code:
defint a-zDECLARE FUNCTION IsLeapYear% (Z) DIM YEAR.MIN AS INTEGER 'Minimum valid year for dates (default=0)DIM DATE.FACTOR AS SINGLE 'Number of days given date is from day zero.DIM WEEK.DAY AS INTEGER 'Day of week value: 1=Sunday....7=Saturday.DIM WEEK.NUM AS INTEGER 'Week number within year (1 to 54).DIM JULIAN.DAY AS INTEGER 'Day number within year (1 to 366).DIM DATE.OK AS INTEGER 'Valid date indicator: -1=True, 0=False.DIM ZYY AS INTEGER 'Value of the 4 digit year.DIM ZMM AS INTEGER 'Value of the 2 digit month.DIM ZDD AS INTEGER 'Value of the 2 digit day.DIM ZDWORK AS LONG 'Variable, internal to date routines.DIM ZFSAVE AS SINGLE 'Variable, internal to date routines.DIM ZFSAVE2 AS SINGLE 'Variable, internal to date routines.DIM ZMO(1 TO 12) AS INTEGERDATA 31,28,31,30,31,30,31,31,30,31,30,31FOR ZMM=1 TO 12:READ ZMO(ZMM):NEXTREM ***************************************************************************print "Enter a date as YYYYMMDD ";input YYYYMMDD$z$=YYYYMMDD$gosub date.factorif not(date.ok) then print YYYYMMDD$;" is an invalid date":systemDayWeek$=mid$("SunMonTueWedThuFriSat",3*WEEK.DAY-2,3)print DayWeek$systemREM ***************************************************************************REM ***** S U B R O U T I N E S REM ***************************************************************************REM *REM *** DATE.FACTOR: PRINCIPAL DATE SUBROUTINE:REM * ======================================REM * - Validate input date string.REM * - Compute number of days (date.factor) from year 0, month 0, day 0.REM * - Compute day of week.REM * - Compute week number.REM * - Compute "julian" day of year.REM * - Compute date of Easter Sunday for given year. (removed)REM *REM * INPUT: REM * =====REM * Z$ = Date string formatted as YYYYMMDD.REM * YEAR.MIN = Minimum year user wishes to allow (default 0)REM *REM * OUTPUT:REM * ======REM * DATE.OK = -1 if input date VALID. (true)REM * = 0 if Input date INVALID. (false) REM * NOTE: IF VALID, THE FOLLOWING VARIABLES AR BASED ON INPUT DATE.REM * IF INVALID, THE VALUES MAY HAVE CHANGED AND ARE MEANINGLESS.REM * DATE.FACTOR = Number of cumulative days from year/month/day 0.REM * WEEK.DAY = 1 to 7 is Sunday to Saturday respectively. REM * WEEK.NUM = 1 TO 54 is week number within year. REM * JULIAN.DAY = 1 TO 366 is day number within year. REM * ZYY = Value of of 4 digit year. REM * ZMM = Value of month. REM * ZDD = Value of day. REM * EASTERSUNDAY$ = Date of Easter for given year. REM * Z$ = (unchanged).REM * YEAR.MIN = (unchanged).REM *REM *REM * Date factor logic adopted from a Texas Instruments calculator manual.REM *DATE.FACTOR: gosub Date.Check 'check input date if not(date.ok) then RETURN 'exit if invalid zmm=1:zdd=1 'set to January 1st gosub Compute.Factor 'compute factor of Jan 1st zfsave=date.factor 'save factor of Jan 1st gosub Compute.Weekday 'week.day now has day of week of Jan 1st zdd=val(right$(z$,2)) 'Restore input date's day + month zmm=val(mid$(z$,5,2)) gosub Compute.Factor 'compute factor of input date '* Julian day is input date minus Jan 1st of same year +1 julian.day=date.factor-zfsave+1 '* Compute the week number: (week.day-1 is week day of Jan 1st relative to 0) week.num=int((julian.day+(week.day-1)-1)/7)+1 '* Compute the day of the week of input date: gosub Compute.WeekdayRETURNCOMPUTE.FACTOR: DATE.FACTOR=365!*ZYY+ZDD+31*(ZMM-1) 'NOTE: WON'T WORK WITHOUT ! AFTER 365. IF ZMM<3 THEN DATE.FACTOR=DATE.FACTOR+INT((ZYY-1)/4)-INT(3/4*(INT((ZYY-1)/100)+1)) ELSE DATE.FACTOR=DATE.FACTOR-INT(.4*ZMM+2.3)+INT(ZYY/4)-INT(3/4*(INT(ZYY/100)+1)) END IFRETURNCOMPUTE.WEEKDAY: '* Compute the day of the week: WEEK.DAY=DATE.FACTOR-INT(DATE.FACTOR/7)*7 'Modulo 7. IF WEEK.DAY=0 THEN WEEK.DAY=7 'WEEK.DAY=1=Sunday.RETURNREM ***************************************************************************REM ********************* DATE.CHECK ****************************************REM *REM *** VALIDATE A DATE IN YYYYMMDD FORMAT.REM *REM * INPUT: Z$ = Given date in format YYYYMMDD.REM * YEAR.MIN = Minimum valid year allowed. (default=0)REM *REM * OUTPUT: DATE.OK = -1 if input date is VALID. (true)REM * 0 if input date is INVALID. (false) REM * (if VALID):REM * ZYY = Value of 4 digit year. REM * ZMM = Value of month. REM * ZDD = Value of day. REM *REM *DATE.CHECK: DATE.OK = 0 'preset to false ZTEMP$="1"+Z$+"1" IF LEN(Z$)<>8 OR MID$(STR$(VAL(ZTEMP$)),2)<>ZTEMP$ THEN RETURN ZDD=VAL(RIGHT$(Z$,2)) 'Set day ZMM=VAL(MID$(Z$,5,2)) 'Set month. ZYY=VAL(LEFT$(Z$,4)) 'Set year. IF ZMM<1 OR ZMM>12 OR ZDD<1 OR ZDD>31 OR ZYY<YEAR.MIN THEN RETURN IF ZMO(ZMM)+1*(-(ZMM=2 AND ISLEAPYEAR(ZYY))) < ZDD THEN RETURN ' If expression (month=2 and is leapyear) is TRUE which is -1, then ' taking the negative of this issues a plus 1. Conversely, the FALSE ' always gives a zero. Multiplying the +1 by this result of 1 or 0 ' will either add 1 or not to the number of days in the month. ' The routine wants to add 1 only when it is February and leap year. DATE.OK = -1 '-1=valid (true)RETURN REM ***************************************************************************END' ====================== ISLEAPYEAR ==========================' Determines if a year is a leap year or not.' ============================================================'FUNCTION IsLeapYear (Z) STATIC ' If the year is evenly divisible by 4 and not divisible ' by 100, or if the year is evenly divisible by 400, then ' it's a leap year: IsLeapYear = (Z MOD 4 = 0 AND Z MOD 100 <> 0) OR (Z MOD 400 = 0)END FUNCTION
Statistics: Posted by moneo — Thu Jun 30, 2005 9:01 pm
Statistics: Posted by Antoni — Thu Jun 30, 2005 4:00 pm
Statistics: Posted by moneo — Wed Jun 29, 2005 8:07 pm
Statistics: Posted by Guest — Wed Jun 29, 2005 8:04 pm
Code:
FUNCTION DayName$ (Y, M, D) IF M > 2 THEN P = M - 3 Q = Y ELSE P = M + 9 Q = Y - 1 END IF Z = (D + Q + Q \ 4 - Q \ 100 + Q \ 400 + CINT(2.6 * P)) MOD 7 DayName$ = MID$("Tue Wed Thu Fri Sat Sun Mon" , 4 * Z + 1, 3)END FUNCTION
Statistics: Posted by Guest — Wed Jun 29, 2005 8:00 pm
Statistics: Posted by Guest — Sun Jun 19, 2005 5:04 pm
Code:
FUNCTION DayName$ (Y, M, D) IF M > 2 THEN P = M - 3 Q = Y ELSE P = M + 9 Q = Y - 1 END IF Z = (D + Q + Q \ 4 - Q \ 100 + Q \ 400 + CINT(2.6 * P)) MOD 7 DayName$ = MID$("Tue Wed Thu Fri Sat Sun Mon" , 4 * Z + 1, 3)END FUNCTION
Statistics: Posted by Antoni — Sun Jun 19, 2005 11:54 am
Statistics: Posted by Guest — Thu Jun 16, 2005 5:10 am
Code:
declare function dow$(y%,m%,d%)declare Function tojulian&(y%,M%,D%) print dow$(2005,6,15)sleepfunction dow$(y%,m%,d%) a&=tojulian&(y%,M%,d%) dow$=mid$("Mon Tue Wed Thu Fri Sat Sun",(a& mod 7)*4+1,3)end functionFunction tojulian&(y%,M%,D%) temp& = (M% - 14) \ 12 JulPart& = D% - 32075 + (1461 * (Y% + 4800 + temp&) \ 4) JulPart& = JulPart& + (367 * (M% - 2 - temp& * 12) \ 12) tojulian& = JulPart& - (3 * ((Y% + 4900 + temp&) \ 100) \ 4)end function
Statistics: Posted by Guest — Wed Jun 15, 2005 2:48 pm
Statistics: Posted by Guest — Sat Jun 11, 2005 2:15 am