Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    Ciclare i giorni tra 2 date

    Salve a tutti,
    devo effettuare un ciclo in giorni dalla data odierna fino ad una data futura.

    Avete qualche idea?

    Grazie

  2. #2
    Utente di HTML.it L'avatar di pietro09
    Registrato dal
    Jan 2002
    Messaggi
    10,116
    codice:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title>Pagina senza titolo</title>
    <script language="javascript" type="text/javascript">
    // <!CDATA[
    
    function Button1_onclick() 
    {
        var di = new Date(2007, 6, 5);
        var df = new Date(2007, 7, 5);
        
        var s = "";
        while(df >= di)
        {
            s += di.toStringDate() + "
    ";
            di.AddDays(1);
        }
        document.getElementById("div1").innerHTML = s;
    }
    
    
    // aggiunta di AddDays a Date
    Date.prototype.AddDays = function (days)
    {
        this.setTime( this.getTime() + days * 86400000 );
    };
    Date.prototype.AddHours = function (hours)
    {
        this.setTime( this.getTime() + hours * 3600000 );
    };
    
    Date.prototype.toStringDate = function ()
    {
        var g = this.getDate(); g = (g < 10)? '0' + g: g;
        var m = (this.getMonth() + 1); m = (m < 10)? '0' + m: m;
        var a = this.getFullYear();
        return g + "/" + m + "/" + a;
    };
    
    // ]]>
    </script>
    </head>
    <body>
        <input id="Button1" type="button" value="button" onclick="return Button1_onclick()" />
        <div id="div1"></div>
    </body>
    </html>
    Pietro

  3. #3

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.