Comparing Dates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bips2005
    New Member
    • Jul 2008
    • 19

    Comparing Dates

    i need to send mail 1 month before expirydate stored in database to a client..till now i can just compare the dates by converting them using strtotime.is there anyways to find out many days are left till expirydate.
  • Muddasir
    New Member
    • Jun 2007
    • 49

    #2
    Hi bips

    here it is what I understood you want to do

    Code:
    //considering this date is being fetch from db and was stored in this format
    $date = "2008-07-15 22:15:58"; 
    
    $date1 = substr($date, 0, 11); 
    
    $date2 = date("Y-m-d"); // current date
    
    $difference = abs(strtotime($date2) - strtotime($date1));
    
    $days = round(((($difference/60)/60)/24), 0); //remaining days
    $date is the expiry date, $date2 is the current date and $days is the total no. of days left till the expiry date.

    Comment

    • hsriat
      Recognized Expert Top Contributor
      • Jan 2008
      • 1653

      #3
      How are you doing that, if you can show some code?

      Comment

      • bips2005
        New Member
        • Jul 2008
        • 19

        #4
        Originally posted by hsriat
        How are you doing that, if you can show some code?
        thank you i finally made the code worked

        Code:
        $chexpiraton = strtotime($expiration);
        	
        	 $today = date("Y-m-d");
        	 $chtoday = strtotime($today);
        	$diff = $chexpiraton - $chtoday;
        	$noday = $diff / (24*60*60);
        $expiration contains date from the database;

        Comment

        • hsriat
          Recognized Expert Top Contributor
          • Jan 2008
          • 1653

          #5
          Originally posted by bips2005
          thank you i finally made the code worked

          Code:
          $chexpiraton = strtotime($expiration);
          	
          	 $today = date("Y-m-d");
          	 $chtoday = strtotime($today);
          	$diff = $chexpiraton - $chtoday;
          	$noday = $diff / (24*60*60);
          $expiration contains date from the database;
          What format is $expiration?.. If its simple UNIX time stamp, then subtract 30*24*60*60 from it and compare it with 'sec' index of gettimeofday array.

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by hsriat
            What format is $expiration?.. If its simple UNIX time stamp, then subtract 30*24*60*60 from it and compare it with 'sec' index of gettimeofday array.
            See his post above. He's already got it to work correctly.

            Comment

            • hsriat
              Recognized Expert Top Contributor
              • Jan 2008
              • 1653

              #7
              Originally posted by r035198x
              See his post above. He's already got it to work correctly.
              Oh, thanks for that :)

              Comment

              Working...