0

I am getting wrong output i.e. 1194908400 None of this is working i.e. I tried to put double quotes around variable, tried without quotation marks. result is same and wrong.

$d='07-11-13';
echo $d;
echo strtotime($d);
echo "<br>";
echo strtotime("$d");
5
  • Isn't strtotime supposed to receive "YYYY-MM-DD"? like $d="2013-11-07"... Commented Nov 7, 2013 at 16:43
  • what output do you want? Commented Nov 7, 2013 at 16:43
  • @briosheje strtotime can accept many different formats: php.net/manual/en/function.strtotime.php I believe you're on to the issue though, the function is confusing the month and day Commented Nov 7, 2013 at 16:44
  • 1
    strotime("2013-11-07") outputs 1383778800 which is correct. You should check php.net/manual/en/function.strtotime.php . Ps: strtotime("07-11-13") outputs 131194908400 to me, which is not correct, if I'm not going wrong :P Commented Nov 7, 2013 at 16:44
  • You need to put in 07-11-2013, that should give you the right time. It's getting confused because it can't work out what format you are using, whether you are using dd-mm-y or y-mm-dd. Commented Nov 7, 2013 at 16:50

4 Answers 4

1

After a few checks, the error is actually NOT in the format you're passing, but rather on the way you're passing it.

What you should do is just replace "13" with "2013":

strtotime("07-11-2013");

output: 1383778800

echo strtotime("2013-11-07");

output: 1383778800

echo strtotime('07-11-13');

output: 1194908400

Sign up to request clarification or add additional context in comments.

Comments

0

The problem is you need to specify a 4 digit year, so that strtime can fully work out which date format you are using. With 07-11-13 it probably thinks you are using 2007-11-13.

Change it to 07-11-2013 and you will get the correct answer.

Comments

0

$d='07-11-13' is wrong, Try this

$d='2013-11-13';
echo $d;
echo strtotime($d);
echo "<br>";
echo strtotime("$d")

Comments

0

strtotime() will accept:

m/d/y
d-m-y

With / it expects month/day and with - it expects day-month.

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.