Date comparison and time limits

Discussion in 'PHP' started by LazyD, Apr 15, 2007.

  1. #1
    I am in need of some help with a date comparison function of sorts.... I am looking for a way to accomplish the following:

    I have a date, in a variable, in MM/DD/YYYY format, this date is an expiration date. Im going to have this script run on cron and run once a day to run the check.

    What I would like it to do is get the expiration date in the variable and compare it to the current date, if the expiration date is 6 months from the current date I want it to email someone or perform some function.

    I am just too confused my date functions, strtotime, mktime, etc.
     
    LazyD, Apr 15, 2007 IP
  2. Nikolas

    Nikolas Well-Known Member

    Messages:
    1,022
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    150
    #2
    You should use timestamps to do this.

    time() will give you the current time in timestamp format, while mysql's UNIX_TIMESTAMP() will give you a date record in timestamp format.
     
    Nikolas, Apr 15, 2007 IP
  3. Subikar

    Subikar Active Member

    Messages:
    241
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Store the date in a variable then explode the date in array
    $ExpDateInArray = explode('/',$Expdate)
    $Day = $ExpDateInArray[0];
    $Month = $ExpDateInArray[1];
    $Year = $ExpDateInArray[2];

    $TimeStampOfExpirationDate = mktime(0,0,0,$Day,$Month, $Year)

    You will get the expiration date timestamp

    And Also get the timestamp of current date.
    $CurrentDateTimeStamp = time();

    if($CurrentDateTimeStamp > $TimeStampOfExpirationDate)
    then email the person
     
    Subikar, Apr 15, 2007 IP