weird date()

admin

Administrator
Staff member
I'm having a weird problem with the date() function.
I've set up the date form to be date("M jS, g:i a", time()+7200);, but for some reason, whenever it is entered into the database, it is entered in as just M jS. I thought it might have been something weird with server, like not recognizing some of those key letters or something, but when i echo out that date form, it does it fine.

here is the code for inserting it:

$title = $_POST['title'];
$message = $_POST['message'];
$timestamp = date("M jS, g:i a", time()+7200);
$message = addslashes($message);
$title = addslashes($title);
$query = mysql_query("INSERT INTO blog (`id`, `title`, `timestamp`, `message`) VALUES (NULL, '$title', '$timestamp', '$message')") or die(mysql_error());Are you inserting into a TIMESTAMP field in MySQL? If so you will need to specify the date as YYYY-MM-DD E.g.:date (Y-m-d, $timestamp);I recently wrote a conversion function for something I was doing. Feel free to dissect, reuse, abuse it. If you want to convert to MySQL the date format I was passing in was dd/mm/yy (european format) /**
* @return string
* @param $date string
* @param $method string
* @desc Convert mysql date to ordinal date or user inputted dates to MySQL format
*/
function mkDate($date, $method = 'FromDB')
{
switch ($method) {

case 'FromDB':
list($year, $month, $day) = explode('-', $date);
$timestamp = mktime(0, 0, 0, $month, $day, $year);
$date = date('j<\sup\>S</\sup> M y', $timestamp);
return $date;
break;

case 'ToDB':
list($day, $month, $year) = explode('/', $date);
$timestamp = mktime(0, 0, 0, $month, $day, $year);
$date = date('Y-m-d', $timestamp);
return $date;
break;

}
}i figured it out, its because i forgot to change the length of the field for the date in the mysql table. when i originally made it, i meant to do a different date form, but then changed it and didnt change the mysql column. haha
 
Back
Top