Qbasicnews.com

Full Version: Dates: more info
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
What is the maximum number of weeks that any year can have?
For those of you that have set up tables or arrays for 52 weeks, or more cleverly for 53 weeks --- the answer is 54.

In a leap year which begins on a Saturday, the last day of the year (December 31st) falls on a Sunday and is the first day of the 54th week.

This condition happens every 28 years. It happened in 1972 and 2000, and blew away many a payroll system that worked on weeks.

Now for the quiz.
1) How do you test if a year is a leap year?
2) How do you know the day of the week for any given date?

Please, just respond with tested solutions, and no other bull. This is intended to help others. Have your fun coding and testing, ok.
(But you seem to have mistaken this for the "Challenge forum". Smile ) (But I couldn't test it because I'm at work goofing off.) (I sure hope they didn't start monitoring this crap yet.)


DIM YEAR AS INTEGER, YEARBY100 AS INTEGER, YEARBY4 AS INTEGER, YEARBY400 AS INTEGER
INPUT "Year"; YEAR
YEARBY100 = YEAR \ 100
IF YEARBY100 * 100 = YEAR THEN
'
' It's a century year (1800, 1900, 2000, etc.).
'
YEARBY400 = YEAR \ 400
IF 400 * YEARBY400 = YEAR THEN PRINT LTRIM$(STR$(YEAR));" is leap."
ELSE
'
' It's not a century year.
'
YEARBY4 = YEAR \ 4
IF 4 * YEARBY4 = YEAR THEN PRINT LTRIM$(STR$(YEAR));" is leap."
END IF
END
Quote:(But you seem to have mistaken this for the "Challenge forum". Smile ) (But I couldn't test it because I'm at work goofing off.) (I sure hope they didn't start monitoring this crap yet.)


DIM YEAR AS INTEGER, YEARBY100 AS INTEGER, YEARBY4 AS INTEGER, YEARBY400 AS INTEGER
INPUT "Year"; YEAR
YEARBY100 = YEAR \ 100
IF YEARBY100 * 100 = YEAR THEN
'
' It's a century year (1800, 1900, 2000, etc.).
'
YEARBY400 = YEAR \ 400
IF 400 * YEARBY400 = YEAR THEN PRINT LTRIM$(STR$(YEAR));" is leap."
ELSE
'
' It's not a century year.
'
YEARBY4 = YEAR \ 4
IF 4 * YEARBY4 = YEAR THEN PRINT LTRIM$(STR$(YEAR));" is leap."
END IF
END
****************************************************
No, it wasn't meant to be a challenge, just more information. If I gave mt version of the answers right away, most people would say "yeah, of course."

Here´s my version of the leap year logic assuming that the input year is a valid integer number between 0001 and 9999:

' Determine if the 4 digit year in Y is a leap year or not:
' Result is L=1 if a leap year, L=0 if not.

' LOGIC: 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.

IF (Y MOD 4 = 0 AND Y MOD 100 <> 0) OR (Y MOD 400 = 0) THEN L=1 ELSE L=0

****************************************************