Link to home
Start Free TrialLog in
Avatar of Imaginx
Imaginx

asked on

converting date formats

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 )
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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;