Re: [PHP] date formatting





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.
.



Relevant Pages

  • Re: [PHP] checking user input of MM-DD-YYYY
    ... Then I would get rid of the MySQL STR_TO_DATE ... I know PHP is loosely typed, ... retrieved as YYYY-MM-DD no matter how you specify it. ... you are letting MySQL do the same thing for you. ...
    (php.general)
  • Re: I am totally stumped..with this on..LOAD_FILE Mysql+PHP= FSCK!!
    ... What I am trying to do is to upload files and stuff them in a mysql database. ... I copied the temporary file to somewhere else, and then handed it to MySQL..THAT WORKED.. ... Is there a way to force a close on the file..maybe that's the problem Mysql is opening a file that is not flushed to disk maybe? ... I gew the feeling its maintaining its own picture of file objects, and doesn't actually flush to the disk unless you do a copy or close php.. ...
    (comp.lang.php)
  • Re: I am totally stumped..with this on..LOAD_FILE Mysql+PHP= FSCK!!
    ... What I am trying to do is to upload files and stuff them in a mysql database. ... I copied the temporary file to somewhere else, and then handed it to MySQL..THAT WORKED.. ... Is there a way to force a close on the file..maybe that's the problem Mysql is opening a file that is not flushed to disk maybe? ... I gew the feeling its maintaining its own picture of file objects, and doesn't actually flush to the disk unless you do a copy or close php.. ...
    (comp.lang.php)
  • Re: com_dotnet
    ... And if MySQL isn't installed, the DLL won't load and phpinfowill show MySQL support isn't enabled. ... The MySQL interface is NOT compiled into PHP on the distributed Windows binaries - or you'd never be able to run PHP unless you had MySQL installed. ... *SOME* extensions are protocols, some are functional resources, and some are just type libraries. ... If you're going to compile the extension into PHP itself, the libraries must be available at compile time, and when you run PHP, or PHP won't load. ...
    (comp.lang.php)
  • Re Re: PHP 5.2.4 <= various mysql functions safemode & open_basedir bypass
    ... > various mysql functions safemode & open_basedir bypass ... PHP is currently very used because it's easy to use. ... Apache has directory restrictions. ... # if the mysql user has perms, ...
    (Bugtraq)