Re: date formatting

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

 




On Wed, August 29, 2007 4:12 pm, Mike Ryan wrote:
> I would like to have my users input the date formate as mm-dd-yyyy
> mysql
> wants the data to come down as yyyy-mm-dd.
>
> The question I have is how do I convert from the mm-dd-yyyy to
> yyyy-mm-dd so
> that I can write it out to the database?

You could tell MySQL to use the mm-dd-yyyy input format I think.  Ask
on a mysql list.

In PHP:

<?php
  if (preg_match('|([0-9]{1,2})-([0-9]{1,2})-([0-9]{4})|', $date,
$parts){
    $m = $parts[1];
    $d = $parts[2];
    $y = $parts[3];
    $date_sql = mysql_real_escape_string("$y-$m-$d"));
  }
  else die("Invalid date input.");
?>

die() is probably a bit extreme for this, but it's a start.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Please vote for this great band:
http://acl.mp3.com/feature/soundandjury/?band=COMPANY-OF-THIEVES

Requires email confirmation.
One vote per day per email limit.
Obvious ballot-stuffing will be revoked.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[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