title image


Smiley Re: Datumsberechnung
Hi Alex,



Test



function KW () {



var kw = "36";

var d = new Date("2006","1"-1,"1"); //Jahr, Monat, Tag

var t = d.getDate();

var gt = d.getDay();

var gm = d.getMonth();

var j = d.getFullYear();

var tagname = new Array("So","Mo","Di","Mi","Do","Fr","Sa");

var mo, tage;

var datum;

var ngt, ngm, ngy;



switch (tagname[gt]) {

case "So":

mo = t+1;

tage = mo + (7 * kw -7);

datum = new Date(j,"1"-1,tage)

ngt = datum.getDate();

ngm = datum.getMonth()+1;

ngy = datum.getFullYear();

document.write ("KW: " + kw + "");

document.write ("Datum : " + ngt + "." + ngm + "." + ngy + "");

break;

case "Mo":

mo = t;

tage = mo + (7 * kw -7);

datum = new Date(j,"1"-1,tage)

ngt = datum.getDate();

ngm = datum.getMonth()+1;

ngy = datum.getFullYear();

document.write ("KW: " + kw + "");

document.write ("Datum : " + ngt + "." + ngm + "." + ngy + "");

break;

case "Di":

mo = t-1;

tage = mo + (7 * kw -7);

datum = new Date(j,"1"-1,tage)

ngt = datum.getDate();

ngm = datum.getMonth()+1;

ngy = datum.getFullYear();

document.write ("KW: " + kw + "");

document.write ("Datum : " + ngt + "." + ngm + "." + ngy + "");

break;

case "Mi":

mo = t-2;

tage = mo + (7 * kw -7);

datum = new Date(j,"1"-1,tage)

ngt = datum.getDate();

ngm = datum.getMonth()+1;

ngy = datum.getFullYear();

document.write ("KW: " + kw + "");

document.write ("Datum : " + ngt + "." + ngm + "." + ngy + "");

break;

case "Do":

mo = t-3;

tage = mo + (7 * kw -7);

datum = new Date(j,"1"-1,tage)

ngt = datum.getDate();

ngm = datum.getMonth()+1;

ngy = datum.getFullYear();

document.write ("KW: " + kw + "");

document.write ("Datum : " + ngt + "." + ngm + "." + ngy + "");

break;

case "Fr":

mo = t-4;

tage = mo + (7 * kw -7);

datum = new Date(j,"1"-1,tage)

ngt = datum.getDate();

ngm = datum.getMonth()+1;

ngy = datum.getFullYear();

document.write ("KW: " + kw + "");

document.write ("Datum : " + ngt + "." + ngm + "." + ngy + "");

break;

case "Sa":

mo = t-5;

tage = mo + (7 * kw -7);

datum = new Date(j,"1"-1,tage)

ngt = datum.getDate();

ngm = datum.getMonth()+1;

ngy = datum.getFullYear();

document.write ("KW: " + kw + "");

document.write ("Datum : " + ngt + "." + ngm + "." + ngy + "");

break;

}

}











Der Quellcode läßt sich natürlich noch optimieren, z. B. die Case-Wiederholung in eine Funktion packen.

Falls Du den Quellcode eingerückt haben möchtest, schicke mir eine PN mit Deiner Mail-Adresse.



Grüße

Guido

geschrieben von

Login

E-Mail:
  

Passwort:
  

Beitrag anfügen

Symbol:
 
 
 
 
 
 
 
 
 
 
 
 
 

Überschrift: