www.webdeveloper.com
Results 1 to 8 of 8

Thread: comparing dates

  1. #1
    Join Date
    May 2003
    Posts
    55

    Post comparing dates

    I need to know how to compare a date with a text string taken from a flat-file. The flat-file will contain a date string (in whatever format is required) and it needs to be compared with the current date, if the current date is past the one in the file it will delete the file. I can code the second part, its the first part im having problems with.

    I'd play with all of PHP's different date settings buy my server has gone tits up at the mo so i thought it would be easier to ask you guys!

    Thanks...

  2. #2
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Something like this should be close...

    PHP Code:
    <?PHP

    $date 
    "06-11-2003";

    $today date("m-d-Y"); #return today's date as MM-DD-YYYY

    if ($today == $date) {
        echo 
    '$today is the same as $date';
    }
    else {
        echo 
    '$today is not the same as $date';
    }

    ?>

  3. #3
    Join Date
    May 2003
    Posts
    55
    thanx pyro but it needs to be if it's equal or greater than today's date, thats what i cant work out.

  4. #4
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    A bit tougher, but not too bad...

    PHP Code:
    <?PHP

    $today 
    time(); #today's date in seconds since January 1, 1970
    $date "06-11-2003";
    $d split("-",$date);
    $date_seconds mktime(0,0,0,$d[0],$d[1],$d[2]); #turn $date into seconds since January 1, 1970
    if ($today $date_seconds) {
        echo (
    "Delete the file");

    else {
        echo (
    "Don't delete the file");
    }

    ?>

  5. #5
    Join Date
    May 2003
    Posts
    55
    You the man pyro!

    Originally posted by pyro
    A bit tougher, but not too bad...

    PHP Code:
    <?PHP

    $today 
    time(); #today's date in seconds since January 1, 1970
    $date "06-11-2003";
    $d split("-",$date);
    $date_seconds mktime(0,0,0,$d[0],$d[1],$d[2]); #turn $date into seconds since January 1, 1970
    if ($today $date_seconds) {
        echo (
    "Delete the file");

    else {
        echo (
    "Don't delete the file");
    }

    ?>

  6. #6
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Thanks...

  7. #7
    Join Date
    Jun 2006
    Posts
    6
    Just found this on Goggle when having the same problems - pyro - over 2 years on and you are still the man.

  8. #8
    Join Date
    Oct 2006
    Posts
    1
    Same issue - found this via Google and had to register just to say thanks - worked as it should!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles