BASIC: What day is it?

By NYYRIKKI

Enlighted (6016)

NYYRIKKI's picture

04-01-2015, 04:56

Wanted to know what day is it... It was harder question than I thought, so maybe better to share the code:

10 INPUT D,M,Y:YL=YMOD100:YH=Y\100:PRINTMID$("SatSunMonTueWedThuFri",((D+VAL(MID
$("622503514624",M,1))+YL+YL\4+((-YH)AND3)*2-((YHAND3)=0)-(M<3)*(((YMOD400)=0)-(
YL>0)*((YAND3)=0)))MOD7)*3+1,3)

RUN
? 4,1,2015
Sun
Ok

Login or register to post comments

By Vampier

Prophet (2409)

Vampier's picture

04-01-2015, 05:41

leap years included?

By NYYRIKKI

Enlighted (6016)

NYYRIKKI's picture

04-01-2015, 07:27

Yes, but the routine supports only positive year numbers. Smile

By meits

Scribe (6530)

meits's picture

04-01-2015, 13:43

That shouldn't be any problem because I don't expect any negative year number soon Smile

By mars2000you

Enlighted (6428)

mars2000you's picture

04-01-2015, 14:39

I guess Nyyrikki was speaking about B.C. years as non supported years.

By PingPong

Prophet (4093)

PingPong's picture

04-01-2015, 18:37

By NYYRIKKI

Enlighted (6016)

NYYRIKKI's picture

04-01-2015, 20:51

Hmm... turning that Zeller formula to BASIC could probably make the code even smaller, but practically this is same thing, just a bit different approach to numbers... Well, how ever I'm just happy that it works... Smile