11

Let me know :)

$add_date = date ("Y-m-d H:m:s"); 
$expiry_date = 'how?';

How to insert into db the $expiry_date for 60 days. mysql format is datetime

1
  • 4
    Was this voted down just because it's a simple question? Let's be a little forgiving, people :) Nov 3, 2009 at 18:25

3 Answers 3

30

Use strtotime():

$start_date = date('Y-m-d H:m:s');
$end_date = date('Y-m-d H:m:s', strtotime("+60 days"));

or more simply:

$end_date = date('Y-m-d H:m:s', time() + 86400 * 60);
0
2

A method avoiding time conversions:

$time = date('Y-m-d H:m:s', time()+3600*24*60)

EDIT
However, it may be less readable and the time saved is probably irrelevant. Plus cletus just edited a similar method into his answer

2

If you are using PHP >= 5.2 I strongly suggest you use the new DateTime object. For example like below:

$add_date = date("Y-m-d H:m:s"); 
$expiry_date = new DateTime($add_date);
$expiry_date ->modify("+60 days");
echo $expiry_date ->format("Y-m-d H:m:s");

Live Demo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.