We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


converting date formats

Imaginx asked
Medium Priority
Last Modified: 2012-06-21
need a function to convert m-d-Y or Y-m-d

i want to run the function anytime a date variable is used & only modify the variable data IF it fits the format to be modified.

in layman's terms:
if( *date* == format m-d-Y){ convert to Y-m-d )
Watch Question

Most Valuable Expert 2011
Author of the Year 2014
Unlock this solution and get a sample of our free trial.
(No credit card required)
Most Valuable Expert 2011
Author of the Year 2014

Your question is a little hard to understand because clients have so many different ways of expressing dates.  Consider this: 03-05-2011.  Do you think that should be March 5 or May 3?  Would you want to convert 03-05-2011 but not convert 03/05/2011?  Would you want to not use ISO8601 formats for some reason?  Questions like that are lurking in the design that seems to underpin your question.  If you can give us a little more context and explanation we may be able to give you a better answer.  In the correct computer science methods, you would do something like this:

$s = '03-05-2011';
$t = strtotime($s);
if (!$t) die("$s is a bogus date string");
$d = date('Y-m-d', $t);
echo $d;
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.