SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP date AND time based condition

    Here's what I want to do:

    If the date is Thu 23rd July 2009 and the time is greater than or equal to 05:00PM then a message is displayed. Otherwise nothing happens.

    I've got this:

    Code:
    <?php
    $d=date("D jS F Y");
    if ($d=="Thu 23rd July 2009")
    echo "It works!";
    ?>
    But I can't for the life of me figure out how to include the time in this script, so that an echo takes place if it is a certain date AND time.

    I also tried this:

    Code:
    <?php
    $d=date("D jS F Y g:iA");
    if ($d=="Thu 23rd July 2009 02:00PM")
    echo "It works!";
    ?>
    But nothing happens - I think I need to have ">=" (Greater than or equal to) somewhere, especially for the time.

    Would appreciate any helps guys.

    Cheers!

  2. #2
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if(time() >= mktime(17007232009))
    {


    If the current time is greater than 23rd july 2009 @ 5pm

  3. #3
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whoa, that's gotta be the fastest reply ever! Cheers for this

    Is the following correct? As I can't seem to get it to display a message to show it works (it's after 2pm (14:00) over here in the UK):

    Code:
    <?php
    if(time() >= mktime(14, 0, 0, 7, 23, 2009)) {
    echo "It works!";
    }
    ?>
    As you've probably guessed, I'm no PHP guru like yourself...

    Cheers again

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is your server based in the UK? Try the following to see what time the server thinks it is:

    PHP Code:
    echo date('H:i'); 

  5. #5
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, spot on, turns out the server time is actually 13.11 so changed time to reflect this (13) and volia, works perfectly!

    Guys, thanks so much, saved me a lot of headaches!

    Really appreciated so thanks again!

  6. #6
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're welcome


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
  •