Act DEV
Act DEV

Reputation: 129

PHP Date function

I meet a trouble with php data function.

echo strtotime("31/05/2011");

It prints empty.

What's problem with this?

Thanks.

Upvotes: 5

Views: 111

Answers (5)

cypher
cypher

Reputation: 6992

How about using php's DateTime functions?

DateTime::createFromFormat('d/m/Y', '31/05/2011');

Upvotes: 1

joakimdahlstrom
joakimdahlstrom

Reputation: 1595

echo strtotime("2011-05-31");

Upvotes: 1

Doug Owings
Doug Owings

Reputation: 4448

For European formatted dates (DD-MM-YYYY) use dashes not slashes:

echo strtotime('31-05-2011');

Upvotes: 1

Brad Christie
Brad Christie

Reputation: 101594

DD/MM/YYYY Is not a valid date format (The manual outlines it must follow one of the supported date and time formats.) So, instead, it should be MM/DD/YYYY:

echo strtotime("05/31/2011");

Or, I guess as others have posted, the european (ISO8601 Notations) version uses hyphens:

echo strtotime("31-05-2011");

Upvotes: 4

Josh
Josh

Reputation: 8191

http://php.net/manual/en/function.strtotime.php

Use dashes instead of forward slashes.

echo strtotime("31-05-2011"); // outputs 1306821600

Upvotes: 1

Related Questions