Re: String to date

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Jun 30, 2008 at 4:58 PM, Mark Bomgardner <mbomgardner@xxxxxxxxx>
wrote:

> 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));
>
> markb
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
> Your date field should always be the same in the database. The just use the
date function to format that date when displaying to the user...don't alter
the date format as it may make the date field unusable for queries or throw
errors when attempting to insert.


-- 

Bastien

Cat, the other other white meat

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux