Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-02-2013, 04:18 PM   PM User | #1
minkoko
New Coder

 
Join Date: Aug 2010
Location: myeik
Posts: 72
Thanks: 4
Thanked 5 Times in 5 Posts
minkoko can only hope to improve
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
__________________
Quote:
Myanmar Web Developer & Designer
http://www.cyberoot.com
minkoko is offline   Reply With Quote
Old 01-04-2013, 10:08 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,498
Thanks: 18
Thanked 361 Times in 360 Posts
sunfighter is on a distinguished road
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?
sunfighter is offline   Reply With Quote
Old 01-04-2013, 11:12 PM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,555
Thanks: 62
Thanked 4,054 Times in 4,023 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is online now   Reply With Quote
Old 01-04-2013, 11:14 PM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,555
Thanks: 62
Thanked 4,054 Times in 4,023 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is online now   Reply With Quote
Old 01-05-2013, 11:11 AM   PM User | #5
minkoko
New Coder

 
Join Date: Aug 2010
Location: myeik
Posts: 72
Thanks: 4
Thanked 5 Times in 5 Posts
minkoko can only hope to improve
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
__________________
Quote:
Myanmar Web Developer & Designer
http://www.cyberoot.com
minkoko is offline   Reply With Quote
Old 01-05-2013, 04:54 PM   PM User | #6
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,498
Thanks: 18
Thanked 361 Times in 360 Posts
sunfighter is on a distinguished road
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
sunfighter is offline   Reply With Quote
Users who have thanked sunfighter for this post:
minkoko (01-05-2013)
Old 01-05-2013, 04:58 PM   PM User | #7
minkoko
New Coder

 
Join Date: Aug 2010
Location: myeik
Posts: 72
Thanks: 4
Thanked 5 Times in 5 Posts
minkoko can only hope to improve
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
__________________
Quote:
Myanmar Web Developer & Designer
http://www.cyberoot.com
minkoko is offline   Reply With Quote
Old 01-05-2013, 06:27 PM   PM User | #8
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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 
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
minkoko (01-06-2013)
Old 01-05-2013, 11:34 PM   PM User | #9
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,555
Thanks: 62
Thanked 4,054 Times in 4,023 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is online now   Reply With Quote
Old 01-06-2013, 12:49 AM   PM User | #10
minkoko
New Coder

 
Join Date: Aug 2010
Location: myeik
Posts: 72
Thanks: 4
Thanked 5 Times in 5 Posts
minkoko can only hope to improve
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 
__________________
Quote:
Myanmar Web Developer & Designer
http://www.cyberoot.com
minkoko is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:41 AM.


Advertisement
Log in to turn off these ads.