Jump to content

inserting into datetime


Lodius2000

Recommended Posts

I am having trouble putting data into a datetime field. I think i have it formatted correctly but i guess not

 

the reason I have all the parts of time separated because each corresponds to default value of a select menu so that you don't always have to enter the current time so.

 

i have tried to simplify the code and use only the parts relevant to make it easier to debug for you guys

 

so the problem is this inserts 0000-00-00 00:00:00 into the database

 

<?php

//db connection using pear db is established


//NOTE: server is on EDT, I live in MDT, thus the -2 for hours
$hours   = (date('G')-2);
$minutes = date('i');
$months	 = date('n');
$days    = date('j');
$years   = date('Y');

$timestamp = ("$years-$months-$days $hours:$minutes:00");


//though the field name is timestamp the mysql field type is DATETIME
$db->query('INSERT INTO text_cms (timestamp) VALUES (?)',
			array($timestamp));

?>

 

whats my problem?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/108604-inserting-into-datetime/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.