我正在使用PHP的MySQL数据库.我使用该DATETIME字段将我的日期值存储在数据库中.
我正在使用这个PHP代码将输入的日期转换为适当的MySQL格式.
date("Y-m-d H:i:s", strtotime($inputDate))
Run Code Online (Sandbox Code Playgroud)
但是,只要日期无效,它就会被放在数据库中 1969-12-31 19:00:00
有没有办法将其默认为0000-00-00 00:00:00?
validateDate()调用时函数不执行的原因是什么?
目的validateDate()是获取类似的字符串01/01/2001并调用isValidDate()以确定日期是否有效.
如果它无效,则会出现警告消息.
function isValidDate(month, day, year){
/*
Purpose: return true if the date is valid, false otherwise
Arguments: day integer representing day of month
month integer representing month of year
year integer representing year
Variables: dteDate - date object
*/
var dteDate;
//set up a Date object based on the day, month and year arguments
//javascript months start at 0 (0-11 instead of 1-12)
dteDate = new Date(year, month, day);
/*
Javascript …Run Code Online (Sandbox Code Playgroud)