Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Aug 2010
    Location
    myeik
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 5 Posts

    php date variable insert in sql problem ?

    Code:
            <?php
            if(isset($_POST['save'])){
                $ar_name = $_POST['ar_name'];
                $ar_dob=$_POST['ar_dob'];
                $ar_city=$_POST['ar_city'];
                $ar_country = $_POST['ar_country'];
                $ar_address = $_POST['ar_address'];
                $ar_teach = $_POST['ar_teach'];
                $ar_profile_photo = $_POST['ar_profile_photo'];
                $ar_prize= $_POST['ar_prize'];
                
                $artist_query= mysql_query("
    INSERT INTO  `tw_gallery`.`artists` (
    `ar_id` ,
    `ar_name` ,
    `ar_dob` ,
    `ar_city` ,
    `ar_country` ,
    `ar_address` ,
    `ar_teach` ,
    `ar_profile_photo` ,
    `ar_prize`
    )
    VALUES (
    NULL ,  '$ar_name',  '$ar_dob',  '$ar_city',  '$ar_country',  '$ar_address',  '$ar_teach',  '$ar_profile_photo', '$ar_prize)'
    );
    
    
                        
    ");
                
                if($artist_query){
                    echo "<meta http-equiv=refresh content=0;url=artists.php>";
                }else{
                   echo "<h1><font color='red'>Not Insert</font></h1>";
                }
                
            }
            ?>
    i want to add my variable $ar_dob to my sql database .
    it work for me but i want to my insert time to sql databse and i pick with date by jquery ui calender

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,301
    Thanks
    23
    Thanked 612 Times in 611 Posts
    You want to insert a time and you want to insert a date?
    Or you want to add a time to jquery ui calender date?
    Where would you get the time?

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,919
    Thanks
    79
    Thanked 4,423 Times in 4,388 Posts
    What does the date that is coming from the datepicker *LOOK* like?

    TO find out, just do
    Code:
    echo "<hr/>date from datepicker::" . $_POST["...name of field..."] . "::<hr/>";
    in your PHP code and then show us what that shows you.

    Use the actual name of the field in the <form> that is changed by the datepicker there, of course.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,919
    Thanks
    79
    Thanked 4,423 Times in 4,388 Posts
    The reason I ask: If the value from the datapicker is in the format "mm/dd/yyyy" or "dd/mm/yyyy" then it won't work with MySQL. MySQL requires format "yyyy-mm-dd". So you need to either re-format the date in your PHP code or use a MySQL function that will convert from the wrong format to the right one.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New Coder
    Join Date
    Aug 2010
    Location
    myeik
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by Old Pedant View Post
    The reason I ask: If the value from the datapicker is in the format "mm/dd/yyyy" or "dd/mm/yyyy" then it won't work with MySQL. MySQL requires format "yyyy-mm-dd". So you need to either re-format the date in your PHP code or use a MySQL function that will convert from the wrong format to the right one.
    yes, My Datetimepicker format is mm/dd/yy from jquery ui site
    and my mysql date format is yyyy-mm-dd so, i can't insert

    So,How to reformat the date or how to change sql format

  • #6
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,301
    Thanks
    23
    Thanked 612 Times in 611 Posts
    Guess you didn't mean "time". The default for Datepicker is "mm/dd/yy", but you can change that. See How to initialize the datepicker with the dateFormat option specified:
    Code:
    $( ".selector" ).datepicker({ dateFormat: "yy-mm-dd" });
    http://api.jqueryui.com/datepicker/ or here with format.Date:
    Code:
    $.datepicker.formatDate( format, date, [settings] )
    http://docs.jquery.com/UI/Datepicker...ker.formatDate

  • Users who have thanked sunfighter for this post:

    minkoko (01-05-2013)

  • #7
    New Coder
    Join Date
    Aug 2010
    Location
    myeik
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 5 Posts
    Thanks mate ,now i see how to format the date for your kindness

    and i just have one question about the time

    can i formate the time like this 9:00 AM to 10:35 PM


    Really thanks sunfighter

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Quote Originally Posted by minkoko View Post
    Thanks mate ,now i see how to format the date for your kindness

    and i just have one question about the time

    can i formate the time like this 9:00 AM to 10:35 PM


    Really thanks sunfighter
    Those are the same format. 9:00 AM = 10:35 PM when it comes to the display format. MySQL uses a 24 hour clock, so display wise you can use PHP to interpret it as you see fit. Since you are using a datetime type in MySQL, php can take that an convert it easily with the datetime class.
    PHP Code:
    $dt = new DateTime($record['datetime']);
    print 
    $dt->format('F j Y g:i A'); // January 5 2013 12:27 PM 

  • Users who have thanked Fou-Lu for this post:

    minkoko (01-06-2013)

  • #9
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,919
    Thanks
    79
    Thanked 4,423 Times in 4,388 Posts
    You can also do all the format conversions in MySQL.

    For example:

    Code:
    INSERT INTO sometable ( someDateTimeField )
    VALUES( STR_TO_DATE( '3/22/2013 3:31pm', '%c/%e/%Y %r') )
    to input 'm/d/yyyy hh:mm:ssAM' values or
    Code:
    SELECT DATE_FORMAT( someDateTimeField,  '%c/%e/%Y %r' ) AS prettyDate
    FROM sometable
    to convert internal format to 'm/d/yyyy hh:mm:ssAM'
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #10
    New Coder
    Join Date
    Aug 2010
    Location
    myeik
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 5 Posts
    OK , Thanks for explain about the date formate to Old Pedant & Fou-Lu & sunfighter

    Now i see how to use that


    I like this method
    PHP Code:
    $dt = new DateTime($record['datetime']); 
    print 
    $dt->format('F j Y g:i A'); // January 5 2013 12:27 PM 


  •  

    Posting Permissions

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