PHP - Formatting multible variables into a mysql DATETIME format
My script receives multiple variables from the user. Each v开发者_运维技巧ariable has part of the date/time (year,month,day,hour,min). All the info is stored in separate variables.
I would like to format all that into an acceptable MySQL DATETIME format so it can be saved in a DB.
The mktime() and strtotime() functions are helpful here. Without an example of what you're working with, I can't give you a better example than the links.
Then you'd format your timestamp with date():
$mysql_date = date('Y-m-d H:i:s', $timestamp);
Perhaps you want
function getDBTime($year, $month, $day $hours, $mins, $secs = "0"){
$timestamp = mktime($hours, $mins, $secs, $month, $day, $year);
return date('Y-m-d H:i:s',$timestamp);
}
and to use $var = getDBTime({your data here});
精彩评论