danthemilk Posted June 17, 2009 Share Posted June 17, 2009 Howdy My form contains select elements for each of the following: year month day hour minute second I need to get that POST data into a valid datetime format like this: 2009-06-19 12:15:00 I have tried $mydatetime = mktime($year, $month, $day, $hour, $minute, $second); but when I trace $mydatetime I get nothing, and I can't insert that value into the database, which is my ultimate goal. Any help with this is greatly appreciated since I'm fairly new to PHP and can't seem to get the google machine working. Link to comment https://forums.phpfreaks.com/topic/162588-solved-simple-form-and-datetime-question/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 17, 2009 Share Posted June 17, 2009 Add the following two lines (for debugging purposes, remove them when you are done) immediately after your first opening <?php tag - ini_set("display_errors", "1"); error_reporting(E_ALL); Link to comment https://forums.phpfreaks.com/topic/162588-solved-simple-form-and-datetime-question/#findComment-858102 Share on other sites More sharing options...
MatthewJ Posted June 17, 2009 Share Posted June 17, 2009 $mydatetime = date('Y-m-d H:i:s', mktime($year, $month, $day, $hour, $minute, $second)); Link to comment https://forums.phpfreaks.com/topic/162588-solved-simple-form-and-datetime-question/#findComment-858120 Share on other sites More sharing options...
danthemilk Posted June 17, 2009 Author Share Posted June 17, 2009 I turned on error reporting and didn't get any error messages. Thanks for your suggestion. This seems like something that would be required all the time. I have the variables for each part of the datetime object, I just need to format them as a datetime object and insert them into my database. Can someone tell me why my $starttime variable: $starttime = mktime($hour, $minute, 00, $month, $day, $year); gets inserted into my database as 0000-00-00 00:00:00? should I be using a function other than mktime? Is there a standard method of inserting a datetime object into a database that I'm missing? Link to comment https://forums.phpfreaks.com/topic/162588-solved-simple-form-and-datetime-question/#findComment-858124 Share on other sites More sharing options...
MatthewJ Posted June 17, 2009 Share Posted June 17, 2009 mktime() returns an integer, using date as I did above to format the output should work okay. Link to comment https://forums.phpfreaks.com/topic/162588-solved-simple-form-and-datetime-question/#findComment-858130 Share on other sites More sharing options...
danthemilk Posted June 17, 2009 Author Share Posted June 17, 2009 Thanks! I didn't see your reply before my last post. I'll let you know if it works for me. Link to comment https://forums.phpfreaks.com/topic/162588-solved-simple-form-and-datetime-question/#findComment-858134 Share on other sites More sharing options...
danthemilk Posted June 17, 2009 Author Share Posted June 17, 2009 Awesome! That took me way longer than it should have. Thank you! Link to comment https://forums.phpfreaks.com/topic/162588-solved-simple-form-and-datetime-question/#findComment-858138 Share on other sites More sharing options...
MatthewJ Posted June 17, 2009 Share Posted June 17, 2009 In looking too, mktime() params should be mktime($hour, $minute, $second, $month, $day, $year) Link to comment https://forums.phpfreaks.com/topic/162588-solved-simple-form-and-datetime-question/#findComment-858141 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.