我有一个格式为 dd-mm-yyyy 的日期值,我想将 DATE 或 DATETIME 值插入 mysql 数据库,但插入始终为 0000-00-00
已经尝试过了,但对我不起作用。
$dateOne = $_POST['dateOne'];
$dateTwo = $_POST['dateTwo'];
$timestamp = date('Y-m-d', strtotime($dateOne));
$ts = date('Y-m-d', strtotime($dateTwo));
PHP部分
$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 部分 - 对于 dateTwo.. dateOne 是一样的
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();
}
从 edittext 和发布参数中获取字符串.. 使用 volley.. 这只是代码的一小部分,因为我认为这里没有问题.. 其他数据插入正确..
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;
}
我预计插入将是实际选择的日期,但插入是 0000-00-00.. 其他数据插入正确..
尚方宝剑之说
倚天杖
至尊宝的传说
相关分类