1

Let's say I have this:

$a11 = date("F j, Y, g:i a", $a['date']); 
$newTime = date($a['date'], strtotime('+3 hour'));
$b11 = date("F j, Y, g:i a", $newTime); 
echo $a11 . " AND " . $b11;

I know $a['date'] is right because I get: March 22, 2011, 10:22 pm. However, the echo produces: March 22, 2011, 10:22 pm AND March 22, 2011, 10:22 pm when clearly the second part is suppose to be three hours ahead.

What am I doing wrong?

2
  • 3
    try 'hours', instead of 'hour' Commented Mar 23, 2011 at 2:58
  • 1
    the s-suffix in 'hours' can be supplied, but will make no difference(it will be ignored). See gnu.org/software/tar/manual/html_node/… Commented Mar 23, 2011 at 3:08

5 Answers 5

5

Don't you want:

$newTime = strtotime( '+3 hours',$a['date'] );
$b11 = date("F j, Y, g:i a", $newTime );
Sign up to request clarification or add additional context in comments.

Comments

1

It seems you provide the wrong order of parameters in $newTime = date($a['date'], strtotime('+3 hour'));. Try this:

<?php
$a['date'] = mktime();
$a11 = date("F j, Y, g:i a", $a['date']); 
$newTime = date(strtotime('+3 hour'),$a['date']);
$b11 = date("F j, Y, g:i a", $newTime); 
echo $a11 . " AND " . $b11;
?>

Comments

0

Dig it, you are not strtotime'ing the $newTime when converting to date, so it's false.

<?php
$a['date'] = time();

$a11 = date("F j, Y, g:i a", $a['date']);

echo 'Now       = ' . time() . PHP_EOL;
echo 'Now +3hrs = ' . strtotime( '+3 hours' ) . PHP_EOL . PHP_EOL;

$newTime = strtotime( '+3 hours' );

$b11 = date("F j, Y, g:i a", $newTime );

echo $a11 . ' and ' . $b11 . PHP_EOL;

Comments

0

The format of date function is: string date ( string $format [, int $timestamp ] ). So, according to the first line, $a['date'] stores the timestamp value. But, according to the second line, its value is date format.

Moreover, you should type "+3 hours".

Comments

0

I add date like following

<?php
$a['date']="March 22, 2011, 10:22 pm";
$a11 = date("F j, Y, g:i a", strtotime($a['date'])); 
$b11 = strtotime(date("F j, Y, g:i a", strtotime($a['date'])) . " +3 hours");
$b11 = date("F j, Y, g:i a", $b11); 
echo $a11 . "AND " . $b11;
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.