RE: [PHP] String to date
| From: | Boyd, Todd M. | Date: | Mon, 30 Jun 2008 21:44:27 +0000 |
| Subject: | RE: [PHP] String to date | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-276143@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Mark Bomgardner [mailto:mbomgardner@kletc.org]
> Sent: Monday, June 30, 2008 3:58 PM
> To: php-general@lists.php.net
> Subject: [PHP] String to date
>
> I need to convert a date retrieved from user input to a mysql date.
> Here
> the problem, I need to convert one of three possible combinations,
> either
> 01/01/2008,01-01-2008 or 01.01.2008. I can't use explode because it's
> limited to one character to explode on. I would prefer not to use
> regexp,
> but think I am going to have to. The one part of the code that works
> below
> is using 01/01/2008 format. Any suggestions
>
> echo $olddate = '06/06/2008';
> echo "<br />";
> echo $olddate2 = '06-16-2008';
> echo "<br />";
> echo $olddate3 = '06.26.2008';
> echo "<br />";
> echo $newdate = date("Y-m-d",strtotime($olddate));
> echo "<br />";
> echo $newdate2 = date("Y-m-d",strtotime($olddate2));
> echo "<br />";
> echo $newdate3 = date("Y-m-d",strtotime($olddate3));
Step 1.) Replace all "-" with "/".
Step 2.) Replace all "." with "/".
Step 3.) Err.. wait.. you're done.
Todd Boyd
Web Programmer