user2619187
user2619187

Reputation: 25

How can i add days to time stamp

How can i add days to time stamp and echo the time. I tried and able to add days to it but when echo it shows a no's.

$timestamp = strtotime('+7 days', $row['sdate']);

Is this code is correct.

Thankyou

Upvotes: 1

Views: 5507

Answers (2)

Konstig
Konstig

Reputation: 135

Strtotime function wants unix timestamp, so you need to convert your time (that i expect is normal datetime)?

strtotime('+7 days', strtotime($row['sdate']) );

Then if you want to format it to datetime again you do like this:

$timestamp = strtotime('+7 days', strtotime($row['sdate']) );
echo date("Y-m-d H:i:s", $timestamp);

You can read more about strtotime and date on php's manual. http://php.net/manual/en/function.strtotime.php

http://php.net/manual/en/function.date.php

Upvotes: 0

GautamD31
GautamD31

Reputation: 28763

It should be like

$date = strtotime($row['sdate']);
$date = strtotime("+7 day", $date);
echo date('Y-m-d H:i:s',$date);

OR you can also try like

$date = strtotime('+7 days', strtotime($row['sdate']) );
echo date('Y-m-d',$date);

Upvotes: 3

Related Questions