?
Solved

converting date formats

Posted on 2011-04-19
2
Medium Priority
?
297 Views
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 )
0
Comment
Question by:Imaginx
  • 2
2 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 1000 total points
ID: 35431835
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 35431856
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;
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month16 days, 13 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question