SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Date Changer

  1. #1
    SitePoint Member
    Join Date
    Jan 2006
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Date Changer

    I use this code:

    PHP Code:
    <script language=JavaScript>


            var 
    mydate=new Date()
            var 
    year=mydate.getYear()

            if (
    year<2000)
                    
    year=1900+year
            
            
    var day=mydate.getDay()
            var 
    month=mydate.getMonth()
            var 
    daym=mydate.getDate()

            if (
    daym<10)
                    
    daym=""+daym

            
    var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
            var 
    montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
                    
    document.write(""+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+"")


                        
    </script> 
    To make the date change automatically on a few of my sites. Is it anyway to change it to display dates a few days ahead.

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Don't use getYear() as it is not Y2K compliant. Some browsers will retrieve 6 as the current year while others will retrieve 106. Use getFullYear() instead (which will always retrieve 2006 for the current year).

    To display 10 days ahead add the following immediately after defining mydate:

    mydate.setDate(mydate.getDate()+10);
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Member
    Join Date
    Jan 2006
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, everything is working.


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
  •