Lodius2000 Posted June 3, 2008 Share Posted June 3, 2008 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 More sharing options...
DarkWater Posted June 3, 2008 Share Posted June 3, 2008 Just use NOW(). It's a MySQL function. Link to comment https://forums.phpfreaks.com/topic/108604-inserting-into-datetime/#findComment-556987 Share on other sites More sharing options...
Lodius2000 Posted June 3, 2008 Author Share Posted June 3, 2008 but NOW() means right now...this second.... right? I need to back date some submissions and for some reason when I try to alter the field in phpmyadmin it wont do it so I need to do it in php Link to comment https://forums.phpfreaks.com/topic/108604-inserting-into-datetime/#findComment-557004 Share on other sites More sharing options...
DarkWater Posted June 3, 2008 Share Posted June 3, 2008 Okay, then make it: SUBDATE(NOW(), INTERVAL 2 DAY) Link to comment https://forums.phpfreaks.com/topic/108604-inserting-into-datetime/#findComment-557006 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.