nofel — 2010-08-29T05:05:34-04:00 — #1
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?
nofel — 2010-08-29T10:11:20-04:00 — #2
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
cups — 2010-08-29T08:00:43-04:00 — #3
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.
admedia — 2010-08-29T08:06:27-04:00 — #4
// 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.