• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 295
  • Last Modified:

Date calculation

Hello,

I know that today can be calculated like this :

$today = date("F j, Y");

But how can I calculate 1 year after today ?

echo "Today is $today, your subscription is valid until $nextyear";

Anyone know how to calculate $nextyear ?

Thanks
0
kapot
Asked:
kapot
  • 2
  • 2
2 Solutions
 
RoonaanCommented:
$nextyear = date('F j, Y', strtotime('+1 Years'));

-r-
0
 
kapotAuthor Commented:
Thanks, but how can I convert it into MySQL DATETIME format ?
0
 
RoonaanCommented:
$nextyear = date('Y-m-d H:i:s', strtotime('+1 Years'));

-r-
0
 
ixtiCommented:
Also you can do it with MySQL functions (if you need it):

mysql> SELECT DATE_ADD(NOW(), INTERVAL 1 YEAR);
           -> '2006-04-18 16:03:00'

or

mysql> SELECT FROM_UNIXTIME(875996580);
           -> '1997-10-04 22:23:00'
mysql> SELECT DATE_ADD(FROM_UNIXTIME(875996580), INTERVAL 1 YEAR);
           -> '1998-10-04 22:23:00'
0
 
ixtiCommented:
It's usefull, when you have table like (id, name, subscription_date) and want to select subscription_date and 1 year after it:

SELECT DATE_FORMAT(`subscription_date`, '%M %e, %Y') AS `subscription_start`, DATE_FORMAT(DATE_ADD(`subscription_date`, INTERVAL 1 YEAR), '%M %e, %Y') AS `subscription_expire` FROM `table`;
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now