[Solved] How to convert “Day, dd Month yyyy” to “yyyy-mm-dd” in php [duplicate]


if you’re facing the problem of converting a human readable date to numeric values you have to reconsider your design. Your code should work only with 32 or 64 bit epoch values (seconds since 1st January 1970) and then convert them into the appropriate format only when needed.

In any case, just do this:

$time = strtotime(stripslashes("Thursday, 14 August 2014"));
echo date("Y-m-d",$time);

remember to strip out slashes and commas because they can confuse strtotime

I would avoid such a solution because it’s NOT portable. You’ll find PHP versions in which such solution doesn’t work, moreover slightly different input strings could make strtotime to fail and most of all -> locale matters!!!! (i.e. what if the string is in italian language???)

Just work with epoch values and make a conversion only to show them to the end user! 🙂

solved How to convert “Day, dd Month yyyy” to “yyyy-mm-dd” in php [duplicate]