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
UNE JOLIE-HORLOGE ET PAS QU'UN PEU !UNE JOLIE-HORLOGE ET PAS QU'UN PEU ! par neodante
Pour les possesseurs d'iPhone, ça y est Bijin Tokei - qui se traduit littéralement en Français par " Jolie Horloge " - est arrivé et GRATUITEMENT s'il vous plaît ! Après la version Tokyo, Hokkaido, night club, racing, Gal, "pour les mademoiselles'", . voi...
Cliquez pour lire la suite de l'article par neodante TECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICESTECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICES par ROMELARD Fabrice
Animé par: Gaetan Bouveret et Julien Chomarat Business Connectivity Services (BCS) est dans SharePoint 2010 la version 2 de Business Data Catalog (BDC dans SharePoint 2007). Il s'agit de la solution permettant de visualiser des données provenan...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice [DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE[DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE par orion
Comme de nombreux geek, je suis un grand amateur de série TV et je rate régulièrement des épisodes de mes séries préférés. Une solution s'offre à vous avec ce merveilleux site : Tv Gorge - www.tvgorge.com Moteur de recherche à l'appui, vous pouvez ...
Cliquez pour lire la suite de l'article par orion TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Vincent Bellet et Baptiste Giraudier La BI dans SharePoint 2010, Les nouveaux services d'application dans SP2010 et SQL Server Reporting services 2008 R2. La BI dans SharePoint est généralisée pour tous afin de permettre à tous les coll...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
DB-MAIN (9.1.0)DB-MAIN (9.1.0)DB-MAIN is a data-modeling and data-architecture tool. It is designed to help developers and anal... Cliquez pour télécharger DB-MAIN Xilisoft DPG Convertisseur (5.1.37.0120)XILISOFT DPG CONVERTISSEUR (5.1.37.0120)Xilisoft DPG Convertisseur offre aux fans de Nintendo DS une bonne solution leur permettant de dé... Cliquez pour télécharger Xilisoft DPG Convertisseur GraphicsGale (2.01.01)GRAPHICSGALE (2.01.01)GraphicsGale est un logiciel de PixelArt avec de nombreuse fonctionnalités permettant de réalisé ... Cliquez pour télécharger GraphicsGale Architecte 3D (Platinum 2010)ARCHITECTE 3D (PLATINUM 2010)Architecte 3D Platinium vous permet de concevoir facilement les plans votre future maison, de l'é... Cliquez pour télécharger Architecte 3D TeamViewer 5 (TeamViewer 5)TEAMVIEWER 5 (TEAMVIEWER 5)Dépanner un ami,expliquer une manipulation devient un jeu d'enfant.
Prise en main d'un autre ord... Cliquez pour télécharger TeamViewer 5
|