Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: how to display only tuesday date using date function

  1. #1
    Join Date
    Nov 2007
    Posts
    69
    Thanks
    36
    Thanked 0 Times in 0 Posts

    Default how to display only tuesday date using date function

    hi forum
    i have tried by using getDay() to get the week number but what next?i m blank
    i mean i want to show 27th may 2008 this week till monday as the coming tuesday and when it is tuesday that is 27th it should show next tuesday is 3rd june 2008 till next monday and so on
    any idea how should i do that
    pls help
    thanks
    anand
    Last edited by meenakshi; 05-23-2008 at 10:18 AM. Reason: title was not clear

  2. #2
    Join Date
    Nov 2007
    Posts
    69
    Thanks
    36
    Thanked 0 Times in 0 Posts

    Default

    anyone can help me plss?

  3. #3
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,920
    Thanks
    2
    Thanked 267 Times in 262 Posts

    Default

    Hi there meenakshi,

    have a look at this example, it may suit your requirements...
    Code:
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>future planning</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <style type="text/css">
    #info {
        width:20em;
        line-height:2em;
        border:0.2em double #33c;
        font-family:verdana,arial,helvetica,sans-serif;
        font-size:1em;
        color:#006;
        text-align:center;
        background-color:#ccf;
        margin:1.6em auto;
     }
    </style>
    
    <script type="text/javascript">
    
    window.onload=function() {
    
    /*************************************************************
    
      start will generate the day of the week.
      So 1 will set it for Monday and 7 will set it for Sunday.
    
    *************************************************************/
    
       now=new Date();
       yy=now.getUTCFullYear();
       mm=now.getMonth();
       dd=now.getDate();
       start=new Date(2007,0,2);    /* this will produce a Tuesday date add ifinitum */
       days=Math.floor((now-start)/(1000*60*60*24));
    
       dd=dd+(7-(days % 7));        /* dd-(days % 7);would be this weeks Tuesday */
    
       next=new Date(yy,mm,dd).toLocaleDateString().replace('Tuesday,','');
    
       document.getElementById('info').firstChild.nodeValue='Next Tuesday is the '+next+'.';
    }
    
    </script>
    
    </head>
    <body>
    
    <div id="info">&nbsp;</div>
    
    </body>
    </html>
    
    coothead

  4. The Following User Says Thank You to coothead For This Useful Post:

    meenakshi (05-28-2008)

  5. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    coothead,

    You forgot to declare your variables. Your use of the toLocaleDateString method will fail in many languages, and should be formatted slightly differently even for US English. Instead of using toLocaleDateString, the mm values (in this case) should be converted directly to the desired string values. That would also have the effect of dropping 'Tuesday' or 'Tue' and their equivalents in other tongues, no matter what the language on the user's computer.
    Last edited by jscheuer1; 05-23-2008 at 12:02 PM. Reason: missed something
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #5
    Join Date
    Nov 2007
    Posts
    69
    Thanks
    36
    Thanked 0 Times in 0 Posts

    Default

    hi
    wow
    it worked
    thanks a tonne

    smile always
    anand

  7. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    It may work for you now, but how about someone in China, or Mexico? Or how about when you have other scripts or objects on your page that might conflict with the undeclared globals in the code? This is much better:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>future planning</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <style type="text/css">
    #info {
        width:20em;
        line-height:2em;
        border:0.2em double #33c;
        font-family:verdana,arial,helvetica,sans-serif;
        font-size:1em;
        color:#006;
        text-align:center;
        background-color:#ccf;
        margin:1.6em auto;
     }
    </style>
    
    <script type="text/javascript">
    
    window.onload=function() {
    
    /*************************************************************
    
      start will generate the day of the week.
      So 1 will set it for Monday and 7 will set it for Sunday.
    
    *************************************************************/
    var
       now=new Date(),
       yy=now.getFullYear(),
       mm=now.getMonth(),
       dd=now.getDate(),
       start=new Date(2007,0,2),    /* this will produce a Tuesday date add ifinitum */
       days=Math.floor((now-start)/(1000*60*60*24)),
       months=['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
    
       dd=dd+(7-(days % 7));        /* dd-(days % 7);would be this weeks Tuesday */
    
       var next=months[mm] +' '+ dd +', '+  yy;
    
       document.getElementById('info').firstChild.nodeValue='Next Tuesday is '+next+'.';
    }
    
    </script>
    
    </head>
    <body>
    <div id="info">&nbsp;</div>
    </body></html>
    Last edited by jscheuer1; 05-23-2008 at 01:31 PM. Reason: Remove UTC from year, in rare cases it will report wrong year
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #7
    Join Date
    Nov 2007
    Posts
    69
    Thanks
    36
    Thanked 0 Times in 0 Posts

    Default

    wow
    thanks

    i will take care of it for sure
    smile always
    anand

  9. #8
    Join Date
    Nov 2007
    Posts
    69
    Thanks
    36
    Thanked 0 Times in 0 Posts

    Default

    hi there is a little problem with the above code
    what changes i have to do pls let me know
    now today is 27.05.2008 and tuesday and it should show the next tuesday that is 3rd june 2008 but the code is showing the date as 34 may 2008
    pls help what changes have to be done
    Code:
    var
       now=new Date(),
       yy=now.getFullYear(),
       mm=now.getMonth(),
       dd=now.getDate(),
       start=new Date(2007,0,2),    /* this will produce a Tuesday date add ifinitum */
       days=Math.floor((now-start)/(1000*60*60*24)),
       months=['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
    
       dd=dd+(7-(days % 7));        /* dd-(days % 7);would be this weeks Tuesday */
    
       var next=months[mm] +' '+ dd +', '+  yy;
    
       document.getElementById('info').firstChild.nodeValue='Next Tuesday is '+next+'.';
    }
    smile always
    anand

  10. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    <script type="text/javascript">
    
    window.onload=function() {
    
    /*************************************************************
    
      start will generate the day of the week.
      So 1 will set it for Monday and 7 will set it for Sunday.
    
    *************************************************************/
    var
       now=new Date(),
       yy=now.getFullYear(),
       mm=now.getMonth(),
       dd=now.getDate(),
       start=new Date(2007,0,2),    /* this will produce a Tuesday date add ifinitum */
       days=Math.floor((now-start)/(1000*60*60*24)),
       months=['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
    
       dd=dd+(7-(days % 7));        /* dd-(days % 7);would be this weeks Tuesday */
    var nextTue=now.setDate(dd);
       yy=now.getFullYear();
       mm=now.getMonth();
       dd=now.getDate();
       var next=months[mm] +' '+ dd +', '+  yy;
    
       document.getElementById('info').firstChild.nodeValue='Next Tuesday is '+next+'.';
    }
    
    </script>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  11. The Following User Says Thank You to jscheuer1 For This Useful Post:

    meenakshi (05-27-2008)

  12. #10
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,920
    Thanks
    2
    Thanked 267 Times in 262 Posts

    Default

    Hi there meenakshi,

    unlike John, I am only an amateur coder, and do this stuff mainly as a mental stimulant in the hope that it may help stave off encroaching senile dementia.

    As John has pointed out my offering to you may not work in Mexico or China and is littered with undesirable undeclared globals.
    Nevertheless, as you have discovered, his code displays...
    Next Tuesday is May 34, 2008.
    ...which, I imagine, is not really satisfactory to your requirements.
    My code, whilst being infected with a multitude of unacceptable coding displays...
    Next Tuesday is the 03 June 2008.
    Why this happens, I do not know but I am sure that John will be better able to explain.

    coothead

  13. The Following User Says Thank You to coothead For This Useful Post:

    meenakshi (05-27-2008)

Bookmarks

Posting Permissions

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