I have a date value in format dd-mm-yyyy and I want to insert DATE or DATETIME value to mysql database, but the insert is always 0000-00-00
Already tried this but doesnt work for me.
$dateOne = $_POST['dateOne'];
$dateTwo = $_POST['dateTwo'];
$timestamp = date('Y-m-d', strtotime($dateOne));
$ts = date('Y-m-d', strtotime($dateTwo));
PHP part
$name = $_POST['name'];
$myname= $_POST['myName'];
$dateOne = $_POST['dateOne'];
$dateTwo = $_POST['dateTwo'];
$timestampa = date('Y-m-d', strtotime($dateOne));
$tsa = date('Y-m-d', strtotime($dateTwo));
$sql = "INSERT INTO hires_bp (suraduju_od, suraduju_do, id_band, id_producer) VALUES ($timestampa, $tsa, (SELECT id FROM band WHERE band_name = '$myname'), (SELECT id FROM producer WHERE producer_name = '$name'))";
Android / Java part - for dateTwo.. dateOne is the same
mCurrentDate = java.util.Calendar.getInstance();
int year = mCurrentDate.get(java.util.Calendar.YEAR);
int month = mCurrentDate.get(java.util.Calendar.MONTH);
int day = mCurrentDate.get(java.util.Calendar.DAY_OF_MONTH);
DatePickerDialog mDatePicker = new DatePickerDialog(Calendar.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
mDateTwoEditText.setText(dayOfMonth + "-" + (month+1) + "-" + year);
mCurrentDate.set(year, month, dayOfMonth);
}
}, year, month, day);
mDatePicker.show();
}
Getting strings from edittext and posting parameters.. using volley.. here's just a smal part of code cause I think there isn't a problem here.. other data inserts correct..
final String dateOne = mDateOneEditText.getText().toString().trim();
final String dateTwo = mDateOneEditText.getText().toString().trim();
......
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("name", name);
params.put("myName", majName);
params.put("dateOne", dateOne);
params.put("dateTwo", dateTwo);
return params;
}
I expected the insert would be actual picked date, but instead the insert is 0000-00-00.. other data is inserted correctly..