Jump to content

date insert issue


ianhaney50

Recommended Posts

Thank you so much, works perfect

 

I just found another little issue when testing, the record date is being inserted into the mysql table as 00/00/0000 instead of the actual date, I am using datepicker, the INSERT query is below

if ($stmt = $mysqli->prepare("INSERT repairs (customer_name, customer_email, customer_phone, computer_make, computer_model, technician, status, exrdate, exrtime, exstdate, exstime, deltype, comments) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"))

The datepicker coding is below

<script>
  $(function() {
    $( "#exrdate" ).datepicker({
	showButtonPanel: true,
	dateFormat: "dd/mm/yy",
	showOn:"both"
	});
  });
  
  $(function() {
	$( "#exstdate" ).datepicker({
	showButtonPanel: true,
	dateFormat: "dd/mm/yy",
	showOn:"both"
	}); 
});
  </script>

It was working before but not now for some reason

 

the data type in the mysql table is date and has no NULL or default

Link to comment
Share on other sites

You need to put dates into the database in yyyy-mm-dd format so if your datepicker is using dd/mm/yy then the date needs converting.

 

You can do this in SQL with the method shown in this example

 

INSERT INTO table (mydate) VALUES (STR_TO_DATE($datepickerdate, '%d/%m/%y') )

Edited by Barand
Link to comment
Share on other sites

Hi Barand

 

I just added that to the INSERT query so now looks like the following

if ($stmt = $mysqli->prepare("INSERT repairs (customer_name, customer_email, customer_phone, computer_make, computer_model, technician, status, exrdate, exrtime, (STR_TO_DATE($exstdate, '%d/%m/%y') ), exstime, deltype, comments) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"))

I selected 8/11/2015 within the datepicker but has outputted it as 10/4/2015

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.