How to send custom jQuery datepicker date into database/retrieve it?

hey folks,
i am using jQuery datepicker with format of M-dd,yy. and i was wonder as being a newbie in both jQuery as well as php. how do i store it in database or retrieve it from database in the same format?

as i am fairly new to php, i didn’t got what u said but i did got n how to insert it. and will be displaying method require something special to what

If you use the DATE type to store your dates in your mysql database then they will be stored:


So to convert M-dd, yy to say, store something in the correct Mysql you’d use PHP, something basically along the lines of :

$name = "William Hunting" ;
$date = date('Y-m-d', strtotime('Sep 13, 10')) ;

// build an insert query
"insert into yourtable startDay, personName values '$date', '$name'" ;



Not testing for failure, or illegal dates, which youd need to do.

Note the quoting of the values in my simple example which assumes you are escaping the values yourself for security reasons and not using PDO or prepared statements.

Having said that, tinker with your JQuery date picker and see if you cannot just format the return value to be YYYY-MM-DD and save this extra step - or look for one which offers that option.

// insert the date
$input = "8-22,10";
$replace = array("-", ",");
$input = str_replace($replace, "/", $input);
$sql = "INSERT INTO mydates (thedate) VAUES('$mydate')";

// retrieve the date
$sql = "SELECT DATE_FORMAT('mydate', '%c-%d,%y')";
$result = mysql_query($sql);

… and what Cups said regarding validation and security.