1

I have:

PHP code: $date = date("F j, Y, g:i a"); and send this to my datebase

I use

$date = $gg['date'];

to get the date from my datebase When I echo $date -> June 30, 2012, 3:45 pm

The time is already set in the database with mail.php, and in ordertracking.php I'm getting that time and want to add one week to it.

So I want to add one week to: $date = $gg['date'];

 $connection = mysql_connect("localhost","root","") or die ("Can't connect");
mysql_select_db("shoppingcart", $connection) or die ("Can't connect");

$ordertracking = mysql_query("SELECT * FROM `ordertracking` WHERE orderid='$orderid'");
while($gg=mysql_fetch_array($ordertracking))
{
    $progress = $gg['progress'];
    $date = $gg['date'];
}

mysql_close($connection)
MOTIVECODEX
  • 2,624
  • 14
  • 43
  • 78
  • Possible duplicate of http://stackoverflow.com/questions/1047375/php-date-manipulation – robert Jun 30 '12 at 13:55
  • I have tried this `$d = mktime(0,0,0,$month,$day,$year); $end_date = date(“Y m d”,strtotime(“+2 days”,$d));` but it did not work. Also tried `$date = strtotime(date("Y-m-d", strtotime($date)) . " +1 week");` did not work. I did change the variables of course – MOTIVECODEX Jun 30 '12 at 13:56
  • @robert no it's not a dubplicate, my problem is way different than what you have posted. – MOTIVECODEX Jun 30 '12 at 13:57
  • Please edit the question. Also note roberts comment and take a look at the php DateTime Class: http://de.php.net/manual/en/class.datetime.php – Thomas Jun 30 '12 at 13:57

4 Answers4

3

Use the DateTime modify() method

$dt = DateTime::createFromFormat("F j, Y, g:i a", $date);
$dt->modify('+1 week');
echo $dt->format("F j, Y, g:i a");
Whisperity
  • 3,012
  • 1
  • 19
  • 36
Ziumin
  • 4,800
  • 1
  • 27
  • 34
1

Here some simple solution)

$date = date( 'F j, Y, g:i a' );
echo date( 'F j, Y, g:i a', strtotime( $date ) + 7 * 24 * 60 * 60 );
Dmitry Teplyakov
  • 2,898
  • 5
  • 26
  • 46
0

If you wnat to use the strtotime method you would do

$date = date('F j, Y, g:i a', strtotime('2012-06-30 3:45 pm +1 week'));
Kris
  • 6,094
  • 2
  • 31
  • 46
  • This gives me `2012-03-11`, does not fix my problem – MOTIVECODEX Jun 30 '12 at 14:03
  • I updated my code to show you exact time you were using.. How does this not fix your problem? It adds exactly one week like you requested – Kris Jun 30 '12 at 14:06
  • No this will do the same, I do not want to enter the date manually. It is set in the database. I've changed my question, but the problem is fixed with Ziumin's solution. Thank you anyways – MOTIVECODEX Jun 30 '12 at 14:11
0

Can you try this:

$date = 'June 30, 2012, 3:45 pm';

$new_date = date("F j, Y, g:i a",strtotime(date("F j, Y, g:i a", strtotime($date)) . " +1 week"));

Hope this helps.

Sabari
  • 6,205
  • 1
  • 27
  • 36