Asked  7 Months ago    Answers:  5   Viewed   9 times

I really like the strtotime() function, but the user manual doesn't give a complete description of the supported date formats. strtotime('dd/mm/YYYY') doesn't work, it works only with mm/dd/YYYY format.

If I have date in dd/mm/YYYY format, how can I convert it to YYYY-mm-dd? I can do it by using explode() function, but I think there are better solutions.

 Answers

19

Here is the simplified solution:

$date = '25/05/2010';
$date = str_replace('/', '-', $date);
echo date('Y-m-d', strtotime($date));

Result:

2010-05-25

The strtotime documentation reads:

Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed.

Tuesday, June 1, 2021
 
Student
answered 7 Months ago
86

You should point to your vendor/autoload.php at Settings | PHP | PHPUnit when using PHPUnit via Composer.

This blog post has all the details (with pictures) to successfully configure IDE for such scenario: http://confluence.jetbrains.com/display/PhpStorm/PHPUnit+Installation+via+Composer+in+PhpStorm

Related usability ticket: http://youtrack.jetbrains.com/issue/WI-18388

P.S. The WI-18388 ticket is already fixed in v8.0

Wednesday, March 31, 2021
 
ojrac
answered 9 Months ago
44

See http://php.net/strtotime

Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed.

23/03/2011 in m/d/y is invalid, as such the function returns false.

Wednesday, March 31, 2021
 
MKM
answered 9 Months ago
MKM
86

d/m/Y h:i A is irreversible (with strtotime) format, use standard formats or use time() as recommended by Joel & Rocket

PROBLEM

<?php
echo $today = date('d/m/Y h:i A');
echo '<br />';
echo $time = strtotime($today);
echo '<br />';
echo date('d/m/Y h:i A', $time);

OUTPUT

alt text

SOLUTION

<?php
$today = strtotime(date('m/d/Y h:i:s')); <- use appropriate format
// OR 
$today = time(); @credit to Joel & Rocket
Wednesday, March 31, 2021
 
barden
answered 9 Months ago
79

On Mac OS X environment variables available in Terminal and for the normal applications can be different, check the related question for the solution how to make them similar.

Note that this solution will not work on Mountain Lion (10.8).

Saturday, May 29, 2021
 
Nate
answered 7 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share