chennaibala Posted October 8, 2009 Share Posted October 8, 2009 hi frd.... i have a problem in insert date in my sql using php.i have show to user "8-Oct-2009",while inserting it must "2009-Oct-8",because mysql allow yyyy-mon-dd format only.how to change data format while insert?can i use strtok($info, $tokens);?or any suggestion..thanks in advances Link to comment https://forums.phpfreaks.com/topic/176941-problem-in-insert-date-in-my-sql/ Share on other sites More sharing options...
Bricktop Posted October 8, 2009 Share Posted October 8, 2009 Hi chennaibala, Can you not use PHP's date() function to insert the date into the database? Then, when you display it you can display in pretty much any format you need. Hope this helps. Link to comment https://forums.phpfreaks.com/topic/176941-problem-in-insert-date-in-my-sql/#findComment-932911 Share on other sites More sharing options...
cags Posted October 8, 2009 Share Posted October 8, 2009 As Bricktop says, something like this should flip it over... $date = date("Y-m-d", strtotime($date)); Link to comment https://forums.phpfreaks.com/topic/176941-problem-in-insert-date-in-my-sql/#findComment-932918 Share on other sites More sharing options...
chennaibala Posted October 8, 2009 Author Share Posted October 8, 2009 hi Bricktop... thanks for your kind reply...in my site user select the date from Calendar.then date should be display in textbox dd-mon-yyyy format.but mysql not allow that in format to insert. Link to comment https://forums.phpfreaks.com/topic/176941-problem-in-insert-date-in-my-sql/#findComment-932919 Share on other sites More sharing options...
Bricktop Posted October 8, 2009 Share Posted October 8, 2009 Hi chennaibala, It depends on how the Calendar stores the date variable, if you post your code it would be easier for us to give a more definitive answer but you could explode() the date returned from the database and then output it in the desired format. e.g. $newdate = explode($date); echo $newdate[0]; echo $newdate[1]; echo $newdate[2]; But post your code for a more definitive answer. Hope this helps. Link to comment https://forums.phpfreaks.com/topic/176941-problem-in-insert-date-in-my-sql/#findComment-932921 Share on other sites More sharing options...
chennaibala Posted October 8, 2009 Author Share Posted October 8, 2009 here is my piece of coding <input name="zdate" type="text" size="12" id="z1date" > by using Calendar,user wil select date .selected date in dispaly in zdate text box in "8-Oct-2009" format. by using post method,i get date value frm text box $ndate=$_POST["zdate"]; so value present in $ndate is 8-Oct-2009.but these format is not insert in mysql Link to comment https://forums.phpfreaks.com/topic/176941-problem-in-insert-date-in-my-sql/#findComment-932929 Share on other sites More sharing options...
cags Posted October 8, 2009 Share Posted October 8, 2009 I refer you to my previous post. Use the date function to reformat $_POST['zdate'] before storing it in $ndate. Link to comment https://forums.phpfreaks.com/topic/176941-problem-in-insert-date-in-my-sql/#findComment-932931 Share on other sites More sharing options...
chennaibala Posted October 9, 2009 Author Share Posted October 9, 2009 thanks cags..i got solution from tips..great..superb..doubt to verify frm u... $ndate1=$_POST["zdate"]; $date = date("Y-m-d", strtotime($ndate1));..these code run perfect..no problem in it.. when i try by these $date = date("Y-m-d", strtotime($_POST["zdate"]));..i get error..these problem in insert...wht may be problem...??thanks in advances for ur reply... Link to comment https://forums.phpfreaks.com/topic/176941-problem-in-insert-date-in-my-sql/#findComment-933554 Share on other sites More sharing options...
ameyemad Posted October 9, 2009 Share Posted October 9, 2009 what error message to you receive? Link to comment https://forums.phpfreaks.com/topic/176941-problem-in-insert-date-in-my-sql/#findComment-933567 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.