Matt Jameson
Matt Jameson

Reputation: 217

php date not converting properly

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?

Upvotes: 0

Views: 308

Answers (4)

Dev
Dev

Reputation: 672

Try this

$date = "01/08/2013";

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

Upvotes: 0

Companjo
Companjo

Reputation: 1792

This will work

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

Upvotes: 3

Sonu Sindhu
Sonu Sindhu

Reputation: 1792

Try this

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

Hope it will help

Upvotes: 1

DevZer0
DevZer0

Reputation: 13545

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

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

Upvotes: 5

Related Questions