Dag van de datum

Gestart doorTimvz5 reacties168 weergaven

6 berichten · pagina 1 van 1

Timvz

Lid · Topicstarter

Berichten
1.803
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hallo iedereen,

Ik zag op tv iemand die met een formule kon bereken welke dag welke dag van de week op een datum valt/viel.
Dit vond ik interessant en ben op gaan zoeken hoe dit moet en dacht hee laat ik dit is met one2xs delen.


Voor kennis:


Wat is mod 7

Mod 7 is vrij simpel.

Wanneer je de rekensom 4x5 hebt is dit 20.
Als je de rekensom 4x5 in mod7 doet is dit 6. Je moet zovaak mogelijk 7 van het antwoord (in dit geval 20 ) aftrekken.

4x5 in mod 7 is dus

4x5= 6

Hoe het moet

En nu de uitleg smile.

Omdat het een formule is hebben ze eigenlijk de gehele datum in getallen verdeelt. Zo krijg de dag een eigen getal de maand de eeuw en het jaartal.

Hier een overzicht van deze getallen:

Jaartallen:

Getal 0 1 2 3 5 6 0 1 3 4 5 6 1 2 3 4 6 0 1 2 4 5 6 0 2 3 4 5
Jaar 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
Jaar 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
Jaar 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
Jaar 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99

Maanden:

Jan Feb Maa Apr Mei Jun Jul Aug Sep Okt Nov Dec
0 3 3 6 1 4 6 2 5 0 3 5

Eeuwen:

0 voor alle eeuwen die met 15.., 19.., 23.. beginnen
6 voor alle eeuwen die met 16.., 20.., 24.. beginnen
4 voor alle eeuwen die met 17.., 21.., 25.. beginnen
2 voor alle eeuwen die met 18.., 22.., 26.. beginnen

Dagen:

De dag behoud zijn eigen getal !

Nu laat ik met een voorbeeld zien hoe de formule in elkaar zit.
Let op dat wanneer het om een schrikkeljaar gaat je in de formule er 1 moet bij rekenen.

Datum 20 december 2020

Dag: 20 = 20
Maand: dec = 5
Jaar: 20 = 4
Eeuw: 20 = 6

De som in mod 7:
20+5+4+6= 0 (35)

0 = zondag.

20 december 2020 valt dus op een zondag !

Dit hele gedoe is dankzij Lennard ook in een scriptie te vinden smile
[COLOR= #0000BB]<?php 
$datum[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]13 mei 2009[/COLOR][COLOR= #007700];[/COLOR] 

[COLOR= #0000BB]$welke[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/explode"]explode[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000] [/COLOR][COLOR= #007700],[/COLOR] [URL="http://www.php.net/strtolower"]strtolower[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$datum[/COLOR][COLOR= #007700]));[/COLOR] 

[COLOR= #0000BB]$maanden[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]([/COLOR] 
                    [COLOR= #DD0000]januari[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700],[/COLOR] 
                    [COLOR= #DD0000]februari[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #0000BB]3[/COLOR][COLOR= #007700],[/COLOR] 
                    [COLOR= #DD0000]maart[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #0000BB]3[/COLOR][COLOR= #007700],[/COLOR] 
                    [COLOR= #DD0000]april[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #0000BB]6[/COLOR][COLOR= #007700],[/COLOR] 
                    [COLOR= #DD0000]mei[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700],[/COLOR] 
                    [COLOR= #DD0000]juni[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #0000BB]4[/COLOR][COLOR= #007700],[/COLOR] 
                    [COLOR= #DD0000]juli[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #0000BB]6[/COLOR][COLOR= #007700],[/COLOR] 
                    [COLOR= #DD0000]augustus[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #0000BB]2[/COLOR][COLOR= #007700],[/COLOR] 
                    [COLOR= #DD0000]september[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #0000BB]5[/COLOR][COLOR= #007700],[/COLOR] 
                    [COLOR= #DD0000]oktober[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700],[/COLOR] 
                    [COLOR= #DD0000]november[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #0000BB]3[/COLOR][COLOR= #007700],[/COLOR] 
                    [COLOR= #DD0000]december[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #0000BB]5[/COLOR] 
                [COLOR= #007700]);[/COLOR] 
                 
[COLOR= #0000BB]$year[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/strlen"]strlen[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$welke[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]2[/COLOR][COLOR= #007700]]) ==[/COLOR] [COLOR= #0000BB]4[/COLOR] [COLOR= #007700]?[/COLOR] [URL="http://www.php.net/substr"]substr[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$welke[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]2[/COLOR][COLOR= #007700]],[/COLOR] [COLOR= #0000BB]2[/COLOR][COLOR= #007700]) :[/COLOR] [COLOR= #0000BB]$welke[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]2[/COLOR][COLOR= #007700]];[/COLOR] 
[COLOR= #0000BB]$year[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/floor"]floor[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$year[/COLOR] / [COLOR= #0000BB]4[/COLOR][COLOR= #007700]) +[/COLOR] [COLOR= #0000BB]$year[/COLOR][COLOR= #007700];[/COLOR] 

[COLOR= #0000BB]$month[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$maanden[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]$welke[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]]] +[/COLOR] [COLOR= #0000BB]$year[/COLOR] [COLOR= #007700]%[/COLOR] [COLOR= #0000BB]7[/COLOR][COLOR= #007700];[/COLOR] 

[COLOR= #0000BB]$day[/COLOR] [COLOR= #007700]= ([/COLOR] [COLOR= #0000BB]$month[/COLOR] [COLOR= #007700]+[/COLOR] [COLOR= #0000BB]$welke[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700]] ) %[/COLOR] [COLOR= #0000BB]7[/COLOR][COLOR= #007700];[/COLOR] 

[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/strlen"]strlen[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$welke[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]2[/COLOR][COLOR= #007700]]) ==[/COLOR] [COLOR= #0000BB]2[/COLOR][COLOR= #007700]) 
{[/COLOR] 
     
    [COLOR= #0000BB]$welke[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]2[/COLOR][COLOR= #007700]] =[/COLOR] [COLOR= #DD0000]20[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$welke[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]2[/COLOR][COLOR= #007700]]; 

}[/COLOR] 

[COLOR= #0000BB]$leap[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$welke[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]2[/COLOR][COLOR= #007700]] %[/COLOR] [COLOR= #0000BB]4[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #0000BB]0[/COLOR] [COLOR= #007700]||[/COLOR] [COLOR= #0000BB]$welke[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]2[/COLOR][COLOR= #007700]] %[/COLOR] [COLOR= #0000BB]100[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #0000BB]0[/COLOR] [COLOR= #007700]||[/COLOR] [COLOR= #0000BB]$welke[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]2[/COLOR][COLOR= #007700]] %[/COLOR] [COLOR= #0000BB]400[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #0000BB]0[/COLOR] [COLOR= #007700]?[/COLOR] [COLOR= #0000BB]1[/COLOR] [COLOR= #007700]:[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700];[/COLOR] 

[COLOR= #0000BB]$leap[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]6[/COLOR] [COLOR= #007700]-[/COLOR] [COLOR= #0000BB]$leap[/COLOR][COLOR= #007700];[/COLOR] 

[COLOR= #0000BB]$einde[/COLOR] [COLOR= #007700]= ([/COLOR] [COLOR= #0000BB]$day[/COLOR] [COLOR= #007700]+[/COLOR] [COLOR= #0000BB]$leap[/COLOR] [COLOR= #007700]) %[/COLOR] [COLOR= #0000BB]7[/COLOR][COLOR= #007700];[/COLOR] 

[COLOR= #0000BB]$dagen[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]([/COLOR] 
                [COLOR= #DD0000]Zondag[/COLOR][COLOR= #007700],[/COLOR] 
                [COLOR= #DD0000]Maandag[/COLOR][COLOR= #007700],[/COLOR] 
                [COLOR= #DD0000]Dinsdag[/COLOR][COLOR= #007700],[/COLOR] 
                [COLOR= #DD0000]Woensdag[/COLOR][COLOR= #007700],[/COLOR] 
                [COLOR= #DD0000]Donderdag[/COLOR][COLOR= #007700],[/COLOR] 
                [COLOR= #DD0000]Vrijdag[/COLOR][COLOR= #007700],[/COLOR] 
                [COLOR= #DD0000]Zaterdag[/COLOR] 
            [COLOR= #007700]);[/COLOR] 
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$datum[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000] valt op een: [/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$dagen[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]$einde[/COLOR][COLOR= #007700]];[/COLOR]
0
Berichten
380
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?[/COLOR]
[URL="http://www.php.net/setlocale"]setlocale[/URL][COLOR= #007700]([/COLOR]LC_ALL[COLOR= #007700],[/COLOR] [COLOR= #DD0000]nld_nld[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/strftime"]strftime[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"%A"[/COLOR][COLOR= #007700]);[/COLOR]
?>


Voordat mensen dat script daadwerkelijk voor hun website gaan gebruiken
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Best nice smile
toevoeging op 18 december 2012, 151002:
Afbeelding

toevoeging op 18 december 2012, 151007:
faal?

toevoeging op 18 december 2012, 151128:
Lennart schreef:
[COLOR= #0000BB]<?[/COLOR]
[URL="http://www.php.net/setlocale"]setlocale[/URL][COLOR= #007700]([/COLOR]LC_ALL[COLOR= #007700],[/COLOR] [COLOR= #DD0000]nld_nld[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/strftime"]strftime[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"%A"[/COLOR][COLOR= #007700]);[/COLOR]
?>
Voordat mensen dat script daadwerkelijk voor hun website gaan gebruiken

het is nl_NL eh..

toevoeging op 18 december 2012, 151137:
Maar bij mij werkt het voor geen meter smile
0
Thom

Lid

Berichten
10.654
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Bij mij klopt het ook niet.
0
Timvz

Lid · Topicstarter

Berichten
1.803
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Bij mij werkt het prima smile
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Welke server gebruik jij dan?
En welk script?
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren