SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist
    Join Date
    Aug 2010
    Posts
    503
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP If Date Not Working in 2012

    Hi all, I had an if statement which compared two dates, this is now not working since we're in 2012, I can't understand why not. It's going to the second condition. Any help would be appreciated as always

    PHP Code:
    //Check if time hasn't already passed...
        
    if(date('d-m-Y H:i') >= date('d-m-Y H:i'strtotime('21-12-2011 '.$hour.':'.$minute))):
            echo 
    'a';
            
    $target mktime($hour$minute001032012);
            
    $delivery_date date('Y-m-d'strtotime("2012-01-04"));
        elseif(
    date('w') == || date('w') == || date('w') == 0):
            
    //Current day is a Fri, Sat or Sun...
            
    $next_monday date('j'strtotime("next monday"));
            
    $target mktime($hour$minute0date('m'), $next_mondaydate('Y'));
            
    $delivery_date date('Y-m-d'strtotime("next tuesday"));
        elseif(
    date('H:i'strtotime($hour.':'.$minute)) <= date('H:i')):
            
    //Target time is less than real-time...
            
    $next_day date('j')+1;
            
    $target mktime($hour$minute0date('m'), $next_daydate('Y'));
            
    $delivery_date date('Y-m-d'strtotime("+ 2 day"));
        else:
            
    //Everything is just fine...
            
    $target mktime($hour$minute0date('m'), date('j'), date('Y'));
            
    $delivery_date date('Y-m-d'strtotime("+ 1 day"));
        endif; 

  2. #2
    SitePoint Evangelist
    Join Date
    Aug 2010
    Posts
    503
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi all, bit of an update - seems as though I've snookered those on here also!! The problem was with using - in the date. Obviously was getting mixed up with the strtotime functions - 1 week, etc. So instead I've used slashes instead of hyphens.

    PHP Code:
    date('d/m/Y H:i'strtotime(str_replace('-''/''21-12-2011 15:30'))); 
    Hope this helps someone out there should they stumble across this...


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
  •