SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Dec 2000
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,
    I'm currently designing a script that is require to do different stuff depending on date/time of day. Exemple, I want my script to stop letting people sign up and i want another script to start letting people check-in (tourney script) at a certain date/time (that date time would be recorde in a MySQL database). I was wondering if its possible to take current date/time, compare it with the one in my database and do differant stuff depending if its before of after... Can we compare dates in php? Well, there is an easy way to do that i would really enjoy to know it.

    thz

    P.S. This site rules, kevin yank's php&mysql tutorial is awesome!

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The easiest way would be to store the date in the unix timestamp format then compare it to the current unix timestamp For instance if the date from the db was in the unix timestamp format and was stored in a var called $comptime

    $curtime = time();
    if ($curtime < $comptime) {
    print "The current time is earlier than the stored time";
    }

    Hope that helps.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure you can compare time, just put branches in your scripts (if/else) then do what it is needed to.
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  4. #4
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Actually, MySQL can do this quite nicely for you. If each of your 'events' has a column of type TIME, you can then sort your entries in descending order by their time (ORDER BY eventTime DESC LIMIT 1) and use a WHERE clause to select only those entries whose time is less than CURTIME() (WHERE eventTime < CURTIME()). LIMIT the list of results to 1 row to obtain the last event whose time is prior to the current time, and you have your event! If this select produces an empty result set, then the current time is before the first event of the day, so you should do a second select to get the event with the largest TIME value (ORDER BY eventTime DESC LIMIT 1) and do that event.

    Nice and efficient.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference


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
  •