?
Solved

Date calculation

Posted on 2006-04-17
7
Medium Priority
?
286 Views
Last Modified: 2008-02-01
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
Comment
Question by:kapot
  • 2
  • 2
5 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 16467856
$nextyear = date('F j, Y', strtotime('+1 Years'));

-r-
0
 

Author Comment

by:kapot
ID: 16468005
Thanks, but how can I convert it into MySQL DATETIME format ?
0
 
LVL 49

Accepted Solution

by:
Roonaan earned 160 total points
ID: 16468023
$nextyear = date('Y-m-d H:i:s', strtotime('+1 Years'));

-r-
0
 
LVL 6

Expert Comment

by:ixti
ID: 16476771
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
 
LVL 6

Assisted Solution

by:ixti
ixti earned 160 total points
ID: 16476798
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month16 days, 19 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question