Accueil > > > CHOIX DE DATES ET DE PERIODE
CHOIX DE DATES ET DE PERIODE
Information sur la source
Description
Ce code vous permet d'envoyer par formulaire une periode avec ses dates limites, tres utile pour des pages de stats. Au format YYYYMMJJ, mais tres facilement modifiable.
Source
- <HTML>
- <HEAD>
- <TITLE></TITLE>
- <SCRIPT>
- var Today = new Date()
- var Days = new Array("Dimanche","Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi")
- var Months = new Array("Janvier","F¨¦vrier","Mars","avril","Mai","Juin","Juillet","Aout","Septembre","Octobre","Novembre","Décembre")
- var msc_day = 1000*60*60*24
- // retourne la date au format "JJ/MM/AAAA"
- function DateFormat_French(JscDate){
- var sDay = JscDate.getDate() < 10 ? "0" + JscDate.getDate() : JscDate.getDate()
- var sMonth = JscDate.getMonth()+1 < 10 ? "0" + (JscDate.getMonth()+1) : JscDate.getMonth()+1
- return(sDay + "/" + sMonth + "/" + JscDate.getFullYear())
- }
- // retourne la date au format "AAAAMMJJ"
- function DateFormat_Serial(JscDate){
- var sDay = JscDate.getDate() < 10 ? "0" + JscDate.getDate() : JscDate.getDate()
- var sMonth = JscDate.getMonth()+1 < 10 ? "0" + (JscDate.getMonth()+1) : JscDate.getMonth()+1
- return(""+JscDate.getFullYear() + sMonth + sDay)
- }
- // retourne la date du premier jour de la semaine (1 = lundi)
- function Week_FirstDay(FromDate){
- var TestDate = new Date()
- for (j=0; j<=7; j++){
- TestDate.setTime(FromDate.getTime()-(msc_day*j))
- if(TestDate.getDay() == 1){return(TestDate)}
- }
- }
- // retourne le num¨¦ro de la semaine
- function GetWeekNumber(FromDate){
- var tDate = new Date()
- tDate.setTime(FromDate.getTime())
- tDate = Week_FirstDay(tDate)
- for (w=0; w<53; w++){
- if (tDate.getFullYear() != FromDate.getFullYear()){return(w)}
- tDate.setTime(tDate.getTime()-(msc_day*7))
- }
- }
- function ShowDates(Type, iFromNow){
- var DateStart = new Date()
- var DateEnd = new Date()
- var iIndex = 0
- var sTitle = ""
-
- if (Type == "day"){ // type jour donc : d¨¦but de la semaine
- DateStart = Week_FirstDay(DateStart)
- DateStart.setTime(DateStart.getTime()-(msc_day*7*iFromNow))
- DateEnd.setTime(DateStart.getTime()+(msc_day*6))
- sTitle = "Semaine n¡ã " + GetWeekNumber(DateStart)
- }
- else if (Type == "week"){// type semaine donc : d¨¦but et fin de mois
- DateStart.setDate(1)
- for (i=0;i<iFromNow;i++){
- DateStart.setDate(-1)
- DateStart.setDate(1)
- }
- sTitle = Months[DateStart.getMonth()]
- DateEnd.setTime(DateStart.getTime())
- DateEnd.setDate(33)
- DateEnd.setDate(0)
- DateStart = Week_FirstDay(DateStart)
- iIndex = GetWeekNumber(DateStart)
- }
- else if (Type == "month"){// type mois donc : d¨¦but et fin d'ann¨¦e
- var DateStart = new Date()
- DateStart.setDate(1)
- for (i=0;i<iFromNow;i++){
- DateStart.setYear(DateStart.getYear()-1)
- }
- DateStart.setDate(1)
- DateStart.setMonth(0)
- DateEnd.setTime(DateStart.getTime())
- DateEnd.setMonth(11)
- DateEnd.setDate(31)
- iIndex = 1
- sTitle = "Ann¨¦e " + DateStart.getFullYear()
- }
-
- var shtml = "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH='100%'>"
- + "<TR><TD COLSPAN=2 ALIGN='center'>"
- + "<A CLASS='ch_PeriodCursor' HREF=\"javascript: ShowDates('"+Type+"', "+(iFromNow+1)+")\">¡û</A> "
- if (iFromNow > 0)
- {shtml += "<A CLASS='ch_PeriodCursor' HREF=\"javascript: ShowDates('"+Type+"', "+(iFromNow-1)+")\">¡ú</A>"}
- else
- {shtml += "<SPAN CLASS='ch_PeriodCursor Disable'>¡ú</SPAN>"}
- shtml += "</TD></TR>"
- shtml += "<TR><TD COLSPAN=2 CLASS='ch_IntervalTitle'>" + sTitle + "</TD></TR>"
-
- var cDate = new Date()
- var DateEndPeriod = new Date() // fin de la p¨¦riode
- var TodaySerial = DateFormat_Serial(Today) // date d'aujourd'hui au format AAAAMMJJ
- cDate.setTime(DateStart.getTime())
- while (DateFormat_Serial(cDate) <= DateFormat_Serial(DateEnd)){
- var cDateSerial = DateFormat_Serial(cDate) // date courante au format AAAAMMJJ
- if (Type == "day"){
- DateEndPeriod.setTime(cDate.getTime())
- iIndex = cDate.getDate()
- sName = Days[cDate.getDay()]
- }
- else if(Type == "week"){
- DateEndPeriod.setTime(cDate.getTime()+(msc_day*6))
- sName = DateFormat_French(cDate)
- iIndex = GetWeekNumber(cDate)
- }
- else if(Type == "month"){
- DateEndPeriod.setTime(cDate.getTime())
- DateEndPeriod.setDate(33)
- DateEndPeriod.setDate(0)
- sName = Months[cDate.getMonth()]
- }
- if (iIndex < 10){iIndex = "0" + iIndex}
-
- if (DateFormat_Serial(cDate) <= TodaySerial){
- js = "SelectDate("+DateFormat_Serial(cDate)+","+DateFormat_Serial(DateEndPeriod)+",'"+Type+"');"
- sName = "<SPAN CLASS='ch_Index'>" + iIndex + " </SPAN><A ID=\"DateSel\" NAME=\"DateSel\" onclick=\"SelectLink()\" CLASS='ch_Link' STYLE=\"width: 70px\" HREF=\"javascript: "+js+"\">" + sName + "</A>"
- }
- else
- {
- sName = "<SPAN CLASS='ch_Index Disable'>" + iIndex + " </SPAN><SPAN CLASS='ch_Link Disable' STYLE=\"width: 70px\">" + sName + "</SPAN>"
- }
-
- shtml += "<TR><TD>" + sName + "</TD></TR>"
-
- if (Type == "day"){
- cDate.setTime(cDate.getTime()+(msc_day*1))
- }
- else if(Type == "week"){
- cDate.setTime(cDate.getTime()+(msc_day*7))
- }
- else if(Type == "month"){
- cDate.setDate(33)
- cDate.setDate(1)
- iIndex++
- }
- }
- Dates.innerHTML = shtml
- }
-
- function SelectDate(Start, End, sType){
- DateStart.value = Start
- DateFinish.value = End
- Type.value = sType
- }
-
- function SelectLink(){
- oCol = document.getElementsByName(window.event.srcElement.id)
- sClass = "ch_Link"
- for (i=0; i<oCol.length; i++){oCol[i].className = "ch_Link"}
- window.event.srcElement.className = "ch_Link Selected"
- }
- </SCRIPT>
- <STYLE>
- .ch_Title{font: 12 Arial; text-align: center; font-weight: bold; background-color: #DDDDDD}
- .ch_Content{background-color: #F5F5F5; vertical-align: top;}
- .ch_Link{padding-left: 5; padding-right: 5; font: 12 Arial; width: 100%; text-decoration: none;}
- .ch_Link:hover{background-color: #FFFFCC; color: #0000AA;}
- .ch_Index{font: 10 Arial; color: #000000}
- .ch_PeriodCursor{font: 16 Arial; width: 30; font-weight: bold;; text-decoration: none;}
- .ch_IntervalTitle{font: 12 Arial; text-align: center; font-weight: normal;}
- .Selected{background-color: #6699CC; color: #FFFFFF}
- .Disable{cursor: default; color: #AAAAAA;}
- </STYLE>
- </HEAD>
- <BODY>
-
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=1 STYLE="table-layout: fixed">
- <COL WIDTH=70><COL WIDTH=85>
- <TR CLASS="ch_Title"><TD>P¨¦riode</TD><TD>Interval</TD></TR>
- <TR>
- <TD CLASS="ch_Content">
-
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
- <TR><TD><A ID="Period" NAME="Period" onclick="SelectLink()" CLASS="ch_Link" HREF="javascript: ShowDates('day', 0)">Jours</A></TD></TR>
- <TR><TD><A ID="Period" NAME="Period" onclick="SelectLink()" CLASS="ch_Link" HREF="javascript: ShowDates('week', 0)">Semaines</A></TD></TR>
- <TR><TD><A ID="Period" NAME="Period" onclick="SelectLink()" CLASS="ch_Link" HREF="javascript: ShowDates('month', 0)">Mois</A></TD></TR>
- </TABLE>
-
- </TD>
- <TD ID="Dates" CLASS="ch_Content"> </TD>
- </TR>
- </TABLE>
-
- R¨¦sultat :<BR>
- Date d¨¦but : <INPUT TYPE="text" ID="DateStart" NAME="DateStart"><BR>
- Date Fin : <INPUT TYPE="text" ID="DateFinish" NAME="DateFinish"><BR>
- Type : <INPUT TYPE="text" ID="Type" NAME="Type"><BR>
- </BODY>
- </HTML>
<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT>
var Today = new Date()
var Days = new Array("Dimanche","Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi")
var Months = new Array("Janvier","F¨¦vrier","Mars","avril","Mai","Juin","Juillet","Aout","Septembre","Octobre","Novembre","Décembre")
var msc_day = 1000*60*60*24
// retourne la date au format "JJ/MM/AAAA"
function DateFormat_French(JscDate){
var sDay = JscDate.getDate() < 10 ? "0" + JscDate.getDate() : JscDate.getDate()
var sMonth = JscDate.getMonth()+1 < 10 ? "0" + (JscDate.getMonth()+1) : JscDate.getMonth()+1
return(sDay + "/" + sMonth + "/" + JscDate.getFullYear())
}
// retourne la date au format "AAAAMMJJ"
function DateFormat_Serial(JscDate){
var sDay = JscDate.getDate() < 10 ? "0" + JscDate.getDate() : JscDate.getDate()
var sMonth = JscDate.getMonth()+1 < 10 ? "0" + (JscDate.getMonth()+1) : JscDate.getMonth()+1
return(""+JscDate.getFullYear() + sMonth + sDay)
}
// retourne la date du premier jour de la semaine (1 = lundi)
function Week_FirstDay(FromDate){
var TestDate = new Date()
for (j=0; j<=7; j++){
TestDate.setTime(FromDate.getTime()-(msc_day*j))
if(TestDate.getDay() == 1){return(TestDate)}
}
}
// retourne le num¨¦ro de la semaine
function GetWeekNumber(FromDate){
var tDate = new Date()
tDate.setTime(FromDate.getTime())
tDate = Week_FirstDay(tDate)
for (w=0; w<53; w++){
if (tDate.getFullYear() != FromDate.getFullYear()){return(w)}
tDate.setTime(tDate.getTime()-(msc_day*7))
}
}
function ShowDates(Type, iFromNow){
var DateStart = new Date()
var DateEnd = new Date()
var iIndex = 0
var sTitle = ""
if (Type == "day"){ // type jour donc : d¨¦but de la semaine
DateStart = Week_FirstDay(DateStart)
DateStart.setTime(DateStart.getTime()-(msc_day*7*iFromNow))
DateEnd.setTime(DateStart.getTime()+(msc_day*6))
sTitle = "Semaine n¡ã " + GetWeekNumber(DateStart)
}
else if (Type == "week"){// type semaine donc : d¨¦but et fin de mois
DateStart.setDate(1)
for (i=0;i<iFromNow;i++){
DateStart.setDate(-1)
DateStart.setDate(1)
}
sTitle = Months[DateStart.getMonth()]
DateEnd.setTime(DateStart.getTime())
DateEnd.setDate(33)
DateEnd.setDate(0)
DateStart = Week_FirstDay(DateStart)
iIndex = GetWeekNumber(DateStart)
}
else if (Type == "month"){// type mois donc : d¨¦but et fin d'ann¨¦e
var DateStart = new Date()
DateStart.setDate(1)
for (i=0;i<iFromNow;i++){
DateStart.setYear(DateStart.getYear()-1)
}
DateStart.setDate(1)
DateStart.setMonth(0)
DateEnd.setTime(DateStart.getTime())
DateEnd.setMonth(11)
DateEnd.setDate(31)
iIndex = 1
sTitle = "Ann¨¦e " + DateStart.getFullYear()
}
var shtml = "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH='100%'>"
+ "<TR><TD COLSPAN=2 ALIGN='center'>"
+ "<A CLASS='ch_PeriodCursor' HREF=\"javascript: ShowDates('"+Type+"', "+(iFromNow+1)+")\">¡û</A> "
if (iFromNow > 0)
{shtml += "<A CLASS='ch_PeriodCursor' HREF=\"javascript: ShowDates('"+Type+"', "+(iFromNow-1)+")\">¡ú</A>"}
else
{shtml += "<SPAN CLASS='ch_PeriodCursor Disable'>¡ú</SPAN>"}
shtml += "</TD></TR>"
shtml += "<TR><TD COLSPAN=2 CLASS='ch_IntervalTitle'>" + sTitle + "</TD></TR>"
var cDate = new Date()
var DateEndPeriod = new Date() // fin de la p¨¦riode
var TodaySerial = DateFormat_Serial(Today) // date d'aujourd'hui au format AAAAMMJJ
cDate.setTime(DateStart.getTime())
while (DateFormat_Serial(cDate) <= DateFormat_Serial(DateEnd)){
var cDateSerial = DateFormat_Serial(cDate) // date courante au format AAAAMMJJ
if (Type == "day"){
DateEndPeriod.setTime(cDate.getTime())
iIndex = cDate.getDate()
sName = Days[cDate.getDay()]
}
else if(Type == "week"){
DateEndPeriod.setTime(cDate.getTime()+(msc_day*6))
sName = DateFormat_French(cDate)
iIndex = GetWeekNumber(cDate)
}
else if(Type == "month"){
DateEndPeriod.setTime(cDate.getTime())
DateEndPeriod.setDate(33)
DateEndPeriod.setDate(0)
sName = Months[cDate.getMonth()]
}
if (iIndex < 10){iIndex = "0" + iIndex}
if (DateFormat_Serial(cDate) <= TodaySerial){
js = "SelectDate("+DateFormat_Serial(cDate)+","+DateFormat_Serial(DateEndPeriod)+",'"+Type+"');"
sName = "<SPAN CLASS='ch_Index'>" + iIndex + " </SPAN><A ID=\"DateSel\" NAME=\"DateSel\" onclick=\"SelectLink()\" CLASS='ch_Link' STYLE=\"width: 70px\" HREF=\"javascript: "+js+"\">" + sName + "</A>"
}
else
{
sName = "<SPAN CLASS='ch_Index Disable'>" + iIndex + " </SPAN><SPAN CLASS='ch_Link Disable' STYLE=\"width: 70px\">" + sName + "</SPAN>"
}
shtml += "<TR><TD>" + sName + "</TD></TR>"
if (Type == "day"){
cDate.setTime(cDate.getTime()+(msc_day*1))
}
else if(Type == "week"){
cDate.setTime(cDate.getTime()+(msc_day*7))
}
else if(Type == "month"){
cDate.setDate(33)
cDate.setDate(1)
iIndex++
}
}
Dates.innerHTML = shtml
}
function SelectDate(Start, End, sType){
DateStart.value = Start
DateFinish.value = End
Type.value = sType
}
function SelectLink(){
oCol = document.getElementsByName(window.event.srcElement.id)
sClass = "ch_Link"
for (i=0; i<oCol.length; i++){oCol[i].className = "ch_Link"}
window.event.srcElement.className = "ch_Link Selected"
}
</SCRIPT>
<STYLE>
.ch_Title{font: 12 Arial; text-align: center; font-weight: bold; background-color: #DDDDDD}
.ch_Content{background-color: #F5F5F5; vertical-align: top;}
.ch_Link{padding-left: 5; padding-right: 5; font: 12 Arial; width: 100%; text-decoration: none;}
.ch_Link:hover{background-color: #FFFFCC; color: #0000AA;}
.ch_Index{font: 10 Arial; color: #000000}
.ch_PeriodCursor{font: 16 Arial; width: 30; font-weight: bold;; text-decoration: none;}
.ch_IntervalTitle{font: 12 Arial; text-align: center; font-weight: normal;}
.Selected{background-color: #6699CC; color: #FFFFFF}
.Disable{cursor: default; color: #AAAAAA;}
</STYLE>
</HEAD>
<BODY>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=1 STYLE="table-layout: fixed">
<COL WIDTH=70><COL WIDTH=85>
<TR CLASS="ch_Title"><TD>P¨¦riode</TD><TD>Interval</TD></TR>
<TR>
<TD CLASS="ch_Content">
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD><A ID="Period" NAME="Period" onclick="SelectLink()" CLASS="ch_Link" HREF="javascript: ShowDates('day', 0)">Jours</A></TD></TR>
<TR><TD><A ID="Period" NAME="Period" onclick="SelectLink()" CLASS="ch_Link" HREF="javascript: ShowDates('week', 0)">Semaines</A></TD></TR>
<TR><TD><A ID="Period" NAME="Period" onclick="SelectLink()" CLASS="ch_Link" HREF="javascript: ShowDates('month', 0)">Mois</A></TD></TR>
</TABLE>
</TD>
<TD ID="Dates" CLASS="ch_Content"> </TD>
</TR>
</TABLE>
R¨¦sultat :<BR>
Date d¨¦but : <INPUT TYPE="text" ID="DateStart" NAME="DateStart"><BR>
Date Fin : <INPUT TYPE="text" ID="DateFinish" NAME="DateFinish"><BR>
Type : <INPUT TYPE="text" ID="Type" NAME="Type"><BR>
</BODY>
</HTML>
Historique
- 18 juillet 2004 17:49:22 :
- bug sur l'affichage du titre
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3 par ROMELARD Fabrice
Speaker: Bernard Ourghanlian Cette session est comme chaque jour transmise en live par BrainSonic, et j'ai donc suivi cette troisième pleinière par ce moyen sur mon iPad . Elle est dédiée comme chaque année à la mise en perspective de l'é...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE !MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE ! par Vko
Hier durant une session dédiée aux Techdays 2012, j'ai eu le plaisir d'annoncer la sortie de la Béta 2 de Mishra Reader. C'est quoi ? Pour les utilisateurs, c'est une vraie expérience de lecture de flux RSS sur Windows. Rien à voir avec les produit...
Cliquez pour lire la suite de l'article par Vko [FRAMEWORK 4] LES TASKS ET LE THREAD UI[FRAMEWORK 4] LES TASKS ET LE THREAD UI par fathi
Je viens de passer quelques temps au TechDay's et j'ai pu voir pas mal de session intéressante. Par contre une chose m'a un peu étonné lors de certaines de ces sessions qui abordaient les améliorations du framework .NET (donc le 4.5) : en gros, bea...
Cliquez pour lire la suite de l'article par fathi WORKFLOW FOUNDATION 3 A UN PIED DANS LA TOMBEWORKFLOW FOUNDATION 3 A UN PIED DANS LA TOMBE par JeremyJeanson
Depuis déjà un an, je conseille vivement les utilisateurs de Workflow Foundation 3 à migrer vers la version 4. L'information qui va suivre ne devrait donc pas trop prendre au dépourvu les personnes qui m'ont suivi. Je profite de ce poste, pour faire le re...
Cliquez pour lire la suite de l'article par JeremyJeanson TECHDAYS PARIS 2012 : NOUVELLES TENDANCES DU POSTE DE TRAVAIL - BRING YOUR OWN PCTECHDAYS PARIS 2012 : NOUVELLES TENDANCES DU POSTE DE TRAVAIL - BRING YOUR OWN PC par ROMELARD Fabrice
Speakers: Thierry Rapatout, Antoine Petit et Xavier Trebbia Cette session entre dans le cadre des RDV Décideurs des TechDays 2012, elle est liée à la consumérisation de l'IT et la mise en place du "DeskTop as a Service" dans de plus en ...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|