Jump to content

SpiderT3

New Members
  • Posts

    1
  • Joined

  • Last visited

    Never

Everything posted by SpiderT3

  1. I've been trying to figure out how to subtract two dates to get the number of months between the two dates. It was frustrating at first because I was using a timestamp, and subtracting the two dates to figure out the seconds in between the two dates. But since each month has different amount of days in each of them, each month is not the same amount of seconds either. I finally figured it out, and its pretty simple. Check it out. I basically am working with the format of "YYYY-MM-DD" and am using it to calculate if a trial period has been used up in a subscription website I'm building. So I take todays date and the person's signup date, and calculate the difference in months by multiplying the year by twelve and add it to the number month. subtract the two and there we go! It's so nice when its that simple, reminds me of high school when you were doing fractions, you just have to find the "common denominator"! Because I'm using a cron job to execute this on the same day each month, I don't need to worry about calculating days. $subscription_start = strtotime($subscr_change); $now = strtotime($today); function total_months($a){ $year = date("Y", $a); $ymonths= $year * 12; $month = date("n", $a); $total = $ymonths + $month; return $total; } $dif = abs(total_months($subscription_start) - total_months($today));
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.