0

I have this date in php: 31/01/2013

I'm trying to convert it using the strtotime function like so

date("Y-m-d", strtotime(31/01/2013));

but it keeps displaying as 1970-01-01. Any know why this is?

2
  • 4
    strtotime expects a string - not a number. Commented Aug 1, 2013 at 8:46
  • 1
    31 divided by 01 divided by 2013 equals 0.0153999006458023, which is cast to integer 0; which is the unix timestamp for 1st January 1970 at 00:00 GMT Commented Aug 1, 2013 at 8:57

4 Answers 4

5

you should include it inside a string, not a continuous series of dividing numbers

date("Y-m-d", strtotime("31/01/2013"));
Sign up to request clarification or add additional context in comments.

Comments

3

This will work

$date = str_replace("/", "-", "31/01/2013");
echo date("Y-m-d", strtotime($date));

Comments

1

Try this

$date = "31/01/2013";
$date = date("Y-m-d", strtotime($date));

Hope it will help

Comments

0

Try this

$date = "01/08/2013";

echo date('Y-m-d', $date);

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.