Results 1 to 2 of 2

Thread: Adding date increments to table headers

  1. #1
    Join Date
    Nov 2012

    Post Adding date increments to table headers


    I'm trying to add dates inside table headers starting from the current date and increment it for about 3 weeks.
    This is what I have done in my script.js

    function insertDate(){
    for (var i=0; i<24; i++) {
    var currentTime = new Date()
    var month = currentTime.getMonth() + 1
    var day = currentTime.getDate()
    var year = currentTime.getFullYear()
    var currDate = day + "." + month + "." + year

    document.getElementById("head" + i).innerHTML = currDate;


    But it is not showing any date inside the table headers. Could some help or tell me what I am doing wrong.

  2. #2
    Join Date
    Oct 2010
    Versailles, France
    You actually have a table with 24 cells (<td id="head1"></td>... <td id="head24"></ td>) ?
    You really call the function with an event or an instruction insertDate() ?
    Are the preceding tags present in the body during this call ?

    You have to update the current date in the loop and to call currDate.toLocaleString() or currDate.toUTCString(), or to build your date format to display something readable...

    Try this for the loop
    <div id="pge">
    <ul id="lst"></ul>
    // The script at the end of the body : the list container exists when we call setDates().
    <script type="text/javascript">
    var mns='January,February,March,April,May,June,July,August,September,October,November,December'.split(',');
    function setDates(){
    	// The initial current date
    	var crtDte=new Date()
    	for (var i=0;i<24;i++){
    		// One day later
    		document.getElementById('lst').innerHTML+='<li>'+crtDte.getDate()+' '+mns[+crtDte.getMonth()]+' '+crtDte.getFullYear()+'</li>';
    Last edited by 007Julien; 11-27-2012 at 07:00 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center