January 19, 2021, 06:21:14 AM

### Author Topic: [bmx] Weekday of a date (BlitzMax) by wedoe [ 1+ years ago ]  (Read 858 times)

#### BlitzBot

• Jr. Member
• Posts: 1
##### [bmx] Weekday of a date (BlitzMax) by wedoe [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
Title : Weekday of a date (BlitzMax)
Author : wedoe
Posted : 1+ years ago

Description : This code will give you the correct weekday of any date between 1772 and 2099 !

Code :
Code: BlitzMax
1. '------------------------------- DOD (Day of date)
2. Function dod\$(day,month,year) ' (DD,MM,YYYY)
3. Local d,a,m,y,tp\$
4.
5. a=14-month
6. a=a/12
7. y=year-a
8. m=month+(12*a)-2
9.
10. d=(day+y+(y/4)-(y/100)+(y/400)+((31*m)/12)) Mod 7
11.
12. Select d
13.  Case 0 tp\$="Sunday "
14.  Case 1 tp\$="Monday "
15.  Case 2 tp\$="Tuesday"
16.  Case 3 tp\$="Wednesday "
17.  Case 4 tp\$="Thursday"
18.  Case 5 tp\$="Friday "
19.  Case 6 tp\$="Saturday "
20. End Select
21.
22. Return tp\$                      ' Return day
23. End Function

Airilsm(Posted 1+ years ago)

Wow, very helpful addition.I believe many people don't know how that calculation work but it's work!! Very simple and short formula.thanks for sharing

n8r2k(Posted 1+ years ago)

i dont have a clue what your doing, but why only 1772-2009?

stayne(Posted 1+ years ago)

2099

H&K(Posted 1+ years ago)

Thats when the world is penciled in to end.

xlsior(Posted 1+ years ago)

wedoe(Posted 1+ years ago)

<div class="quote"> ...The 1772 is probably due to the switch-over from the Julian calendar to the gregorian calendar </div> Spot on !That's when they switched from Julian to Gregorian in my Country )In Italy, Poland, Portugal and Spain it's good from 1552 !The formula should be good until 4099 when an adjustment of the Gregorian calendar is sceduled but I have not testedthe formula beyond 2099. (Had no need for it you see...)<div class="quote"> i dont have a clue what your doing </div> It's not very complex at all, it's the "14" and "-2" that is confusing to mostbut this is only done to make february the last month of the year in the formulaand this way the formula gets a lot more simple when leapyear just add an extra day at the end of the year, not squeezed in as day nr 60 of 366 !

H&K(Posted 1+ years ago)

<div class="quote"> ...until 4099 when an adjustment of the Gregorian calendar is sceduled  </div>The audacity of this astounds me

wedoe(Posted 1+ years ago)

<div class="quote"> The audacity of this astounds me  </div>He he !

Kevin_(Posted 1+ years ago)

Wedoe is a plagiarist<a href="codearcs6a2e.html?code=997" target="_blank">http://www.blitzbasic.com/codearcs/codearcs.php?code=997[/url]

degac(Posted 1+ years ago)

well he missed<div class="quote"> ;Ooouch! </div>on the main formula...and to be correct...<a href="http://quasar.as.utexas.edu/BillInfo/doomsday.html" target="_blank">http://quasar.as.utexas.edu/BillInfo/doomsday.html[/url]

Rook Zimbabwe(Posted 1+ years ago)

Code: [Select]
`; Get the day of the week example by Prof.;Graphics 320,240,0,2SetBuffer BackBuffer()dday\$=Input\$("What day were you born? ")mmonth\$=Input\$("What month were you born? ")yyear\$=Input\$("What year were you born? ")ClsDay\$=GetDayOfTheWeek(dday\$,mmonth\$,yyear\$) ; <- Put any date in hereText 10,10,Day\$FlipWaitKey()EndFunction GetDayOfTheWeek\$(day,month,year) ; Returns the day of the week. ; day, month & year are integers i.e. 15 04 2004  a=(14-month)/12  y=year-a  m=month+(12*a)-2  d=(day+y+(y/4)-(y/100)+(y/400)+((31*m)/12))Mod 7  ;Ooouch!  Select d    Case 0:Weekday\$="Sunday - bonny and blithe, and good and gay"    Case 1:Weekday\$="Monday - Fair of face"    Case 2:Weekday\$="Tuesday - Full of grace"    Case 3:Weekday\$="Wednesday - Full of woe"    Case 4:Weekday\$="Thursday - Far to go"    Case 5:Weekday\$="Friday - Loving and giving"    Case 6:Weekday\$="Saturday - Work for a living"    Default:Weekday=""  End Select  Return Weekday\$End Function`Added 1 little step to make it useful... thatnks Prof and Wedoe!

Xerra(Posted 1+ years ago)

This is an impressive bit of code. I'd shudder trying to work out a simple function to do this myself

wedoe(Posted 1+ years ago)

<div class="quote"> Wedoe is a plagiarist </div> It's not exactly a secret how to do this, I just made a BM version of an old math-book example. I was not aware of your snippet though.If anyone know a formula to calculate moon-fases, 100% correctly, I'd like to know )

wedoe(Posted 1+ years ago)

<div class="quote"> This is an impressive bit of code. I'd shudder trying to work out a simple function to do this myself  </div>I guess you refer to this:d=(day+y+(y/4)-(y/100)+(y/400)+((31*m)/12)) Mod 7It's very simple really, it's just a way to say thatevery 4th year is a leapyear, but not if it's dividableby 100, but still if it's dividable by 400.This is done to make up for the few seconds the calendarmisses by just using ever 4 year as a leapyear.Mod 7 explains itself I guess [/i]