Home > mysql, php > php date add – date math compounded

php date add – date math compounded

php
This will probably be an elementary post for most, but recently, I was working on a problem that required determining the expiration of a membership and to write some rules about auto-renewing that membership 10 days prior to expiration. Instead of writing any kind of painful date math, or having to rely on mysql for dateadd functions, strtotime accomplished what I needed:


$now = time();
//expire the membership in a year
$MembershipExpiration = date('Y-m-d', strtotime('+1 year', $now));
//renew the membership 10 days prior to expiration:
$MembershipRenewal = date('Y-m-d', strtotime('+1 year -10 day', $now));

I just threw in the “-10 day” to see what would happen, and those smart cookies who built php already have it all under control.

Advertisements
Categories: mysql, php
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: