Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Edit date script

    Could someone edit this script so the date is always 2 weeks infront of the actual date?

    <script language="JavaScript">
    <!--
    var now = new Date();
    var days = new Array(
    'Sunday','Monday','Tuesday',
    'Wednesday','Thursday','Friday','Saturday');
    var months = new Array(
    'January','February','March','April','May',
    'June','July','August','September','October',
    'November','December');
    var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();
    function fourdigits(number) {
    return (number < 1000) ? number + 1900 : number;}
    today = days[now.getDay()] + ", " +
    months[now.getMonth()] + " " +
    date + ", " +
    (fourdigits(now.getYear()));
    document.write(today);
    //-->
    </script>


    Thanks

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Something like this?:
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">
    <
    html>
    <
    head>
    <
    title>Untitled Document</title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <
    meta http-equiv="Content-Style-Type" content="text/css">
    <
    meta http-equiv="Content-Script-Type" content="text/javascript">
    <
    script type="text/javascript">
    var 
    now = new Date();
    var 
    days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
    var 
    months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
    var 
    newdate=new Date(now.getFullYear(),now.getMonth(),now.getDate()-14);
    var 
    y=newdate.getFullYear(); var m=newdate.getMonth(); var newdate.getDate();
    d<10?d='0'+d:null;
    onload = function(){
    document.getElementById('dat').firstChild.data=y+' '+months[m]+' '+d+' '+days[newdate.getDay()]
    }
    </script>
    </head>
    <body>
    <div id="dat">&nbsp;</div>
    </body>
    </html> 
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yup, thats exactly what i was after, thanks.

  • #4
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <script>
    
    var mydate=new Date()
    var year=mydate.getYear()
    if (year < 1000)
    year+=1900
    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>
    Can someone please help me and edit this script so rather than it loading today's date, instead, I want it to load the upcoming Thursdays date.

    E.G. At the time of this post, the date should read: Thursday, January 14, 2010.

    Once the 14th passes, the date script would now read: Thursday, January 21, 2010 and so on, I just want it load upcoming Thursdays date only.
    Last edited by Oricalos; 01-09-2010 at 11:51 AM.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,984
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Here you are:-

    Code:
    <script type = "text/javascript">
    
    var myDate = new Date();
    var day = myDate.getDay();
    var thurs = 4 - day;  // Thursday is day 4
    if (thurs < 0) {thurs = thurs + 7}
    myDate.setDate(myDate.getDate() + thurs);
    var year = myDate.getFullYear();
    var day = myDate.getDay();
    var month = myDate.getMonth();  // months in JavaScript are 0-11
    var daym = myDate.getDate();
    if (daym<10) {daym="0" + daym}  // prefix 0
    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>

    But you should really have started a new thread rather than revive this ancient one.

    "Utility is when you have one telephone, luxury is when you have two, opulance is when you have three, and paradise when you have none." - Doug Larson
    Last edited by Philip M; 01-09-2010 at 12:53 PM.

  • #6
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Here you are:-

    Code:
    <script type = "text/javascript">
    
    var myDate = new Date();
    var day = myDate.getDay();
    var thurs = 4 - day;  // Thursday is day 4
    if (thurs < 0) {thurs = thurs + 7}
    myDate.setDate(myDate.getDate() + thurs);
    var year = myDate.getFullYear();
    var day = myDate.getDay();
    var month = myDate.getMonth();  // months in JavaScript are 0-11
    var daym = myDate.getDate();
    if (daym<10) {daym="0" + daym}  // prefix 0
    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>

    But you should really have started a new thread rather than revive this ancient one.

    "Utility is when you have one telephone, luxury is when you have two, opulance is when you have three, and paradise when you have none." - Doug Larson
    I apologize, I wasn't sure which was the right thing to do. Thank you very much for the assistance Phillip M!


  •  

    Posting Permissions

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