SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    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?
    All those who wander aren't lost.

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    If you use the DATE type to store your dates in your mysql database then they will be stored:

    YYYY-MM-DD
    2010-09-13

    So to convert M-dd, yy to say, store something in the correct Mysql you'd use PHP, something basically along the lines of :
    PHP Code:
    $name "William Hunting" ;
    $date date('Y-m-d'strtotime('Sep 13, 10')) ;

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

    Untested

    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.

  3. #3
    SitePoint Member admedia's Avatar
    Join Date
    May 2005
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    // 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.

  4. #4
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    Untested

    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.
    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
    All those who wander aren't lost.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •