Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Internet & the Web (https://www.askmehelpdesk.com/forumdisplay.php?f=177)
-   -   Date and time script (https://www.askmehelpdesk.com/showthread.php?t=16837)

  • Dec 31, 2005, 10:39 AM
    manutd4eva
    Date and time script
    Does anyone know a script where I program in the dates and times and from say 8th January from 5.15 until 7.30 it takes you too page2 and after that it carries on taking you to the normal page then on the next date it does the same again so say the 12th from 8am-8.45.

    Thanks
  • Jan 3, 2006, 03:09 AM
    LTheobald
    It can be done but can you answer one question first:

    Are you using a scripting language such as ASP, PHP or JSP (will make things a LOT easier). If you don't know what I'm on about the answer is no.
  • Jan 3, 2006, 03:25 AM
    manutd4eva
    Thanks I will try php or jsp

    Thanks
  • Jan 3, 2006, 04:55 AM
    LTheobald
    Comparing the dates is the easy part. Using Javascript you can do something like below:

    Code:

    // Get the current date
    var today = new Date();

    // Set the date we want to compare (year,month,day,hours,mins,secs)
    // Note the month starts at 0, not 1.  So 0 = Jan, 1 = Feb, ...,  11 = Dec
    var compare = new Date(2006,00,01,09,00,00)

    // Compare the dates
    if (today > compare) {
        alert("COMPARE IN PAST");
    } else if (today < compare) {
        alert("COMPARE IN FUTURE");
    } else {
        alert("EQUAL");
    }
    </script>

    You could edit that to go into a function that takes a date and returns -1, 0 or 1 depending on the result.

    Throwing the user to another page is also simple and you can just use:

    Code:

    window.location = 'new location';
    The thing that is not easy in Javascript that you want is to have the ability to set what dates and times you want to redirect on. Doing this in Javascript would mean that you would need to have variables containing the dates and times you want to switch at. This is messy and would involve having to open and upload the javascript file each time you want to change a date/time.

    The solution here would be to use a database to store the switch dates and times. That way you could check the DB for a row corresponding to the current date. If the current date has a row in the DB, get the time for the DB. If the time from the DB is before the current time, go to page A. If it's on or after the current time, go to page B. This is where something like PHP comes in.

    I'll write you a PHP script to illustate what I mean. Just give me an hour or two to get round to it.
  • Jan 3, 2006, 04:57 AM
    manutd4eva
    Thanks
    I have heard it is possible in mySQL is that true?
    Thanks

  • All times are GMT -7. The time now is 01:04 AM.