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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Feb 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Anyone know how to auto date change

    I have a date that needs to stay static for one week at a time. Like: "offer ends 5/19/04". Anyone know code that will make that auto change every week to the following week. 5/26/04, 6/2/04 etc.

    Thanks in advance.

  • #2
    Regular Coder
    Join Date
    Aug 2003
    Posts
    565
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I definitly doubt it can be done using HTML or CSS... You should use a server side language. What server are you using? Apache (PHP)? IIS (ASP)? You'll probably find a good answer in the appropriate forum of this board.

  • #3
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Sorry but my script wasn't right
    Last edited by Mr J; 02-27-2004 at 09:18 PM.

  • #4
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Ok, try this


    <HTML>
    <HEAD>
    <TITLE>Document Title</TITLE>

    <script language="JavaScript">
    <!--

    display_date=1 // 0 = no, 1 = yes
    prev=0 // 0 = show previous start week, 1 = show next start week

    function y2k(number){
    return (number < 1000) ? number + 1900 : number
    }

    function showWeek() {
    today = new Date() // get todays date
    year = y2k(today.getYear());
    month = today.getMonth();
    day = today.getDate();
    result=getWeek(year,month,day)
    //alert(data[result])
    }

    function getWeek(year,month,day) {
    newYear = new Date(year,0,1) // get current year
    offset = 8 - newYear.getDay() // get number of days if in part week for start of current year
    if (offset == 8){
    offset = 1
    }

    daynum = ((Date.UTC(y2k(year),month,day,0,0,0) - Date.UTC(y2k(year),0,1,0,0,0)) /1000/60/60/24) + 1 // get number of days
    weeknum = Math.floor((daynum-offset+7)/7) // get week number

    if (weeknum == 0) {
    year--
    prevNewYear = new Date(year,0,1);
    prevOffset = 7 + 1 - prevNewYear.getDay();

    if (prevOffset == 2 || prevOffset == 8){
    weeknum = 53
    }
    else{
    weeknum = 52
    }

    }

    ns=document.getElementById&&!document.all
    display_string=""

    if(display_date==1){

    current_day= today.getDay();
    if(current_day>0){

    if(prev==1){ // previous start week
    days_offset=current_day*(1000*60*60*24)
    start_week=new Date(today-days_offset).toString()
    display_string="Week Commencing "
    }
    else{ // next start week
    today2=new Date().getTime()
    end_day=7 // 6 = saturday, 7 = sunday
    if(current_day>0){
    days_offset= (end_day-current_day)*(1000*60*60*24)
    start_week=new Date(today2+days_offset).toString()
    display_string="Offer Ends "
    }
    }

    }

    if(!ns){
    for(i=0;i<10;i++){display_string+=start_week.charAt(i)}
    for(i=start_week.length-5;i<start_week.length;i++){display_string+=start_week.charAt(i)}
    }
    else{
    for(i=0;i<15;i++){display_string+=start_week.charAt(i)}
    }
    document.getElementById("display").innerHTML=display_string

    }

    return weeknum

    }

    // -->
    </script>

    </HEAD>
    <BODY onload="showWeek()">
    <div id="display"></div>
    </BODY>
    </HTML>


  •  

    Posting Permissions

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