Web Analytics Made Easy -
StatCounter Anyone know how to auto date change - CodingForum

Announcement

Collapse
No announcement yet.

Anyone know how to auto date change

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    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.
    Alex
    yourmusicforums.com

    Comment


    • #3
      Sorry but my script wasn't right
      Last edited by Mr J; Feb 27, 2004, 03:18 PM.
      The silent one.

      The most dangerous thing in the world is an idea.
      The most dangerous person in the world is the one with an idea.

      Comment


      • #4
        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>
        The silent one.

        The most dangerous thing in the world is an idea.
        The most dangerous person in the world is the one with an idea.

        Comment

        Working...
        X