uwannadonkey Posted August 13, 2007 Share Posted August 13, 2007 i put a datetime column in my mysql table what php code do i need to get the time and add it into the table? Quote Link to comment https://forums.phpfreaks.com/topic/64703-solved-newb-question-about-datetime/ Share on other sites More sharing options...
dbo Posted August 13, 2007 Share Posted August 13, 2007 Are you looking for the current time? If so I think there is a function in MySQL that will timestamp stuff for you and you won't need to do this in PHP at all. Otherwise search php.net for date() and time() functions. Quote Link to comment https://forums.phpfreaks.com/topic/64703-solved-newb-question-about-datetime/#findComment-322646 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 i have created a table for battle logs. i want to record the time of battle i added the columns ID, winner, loser, and TIME(datetime) when i added first battle there was no time, how do i add that ? Quote Link to comment https://forums.phpfreaks.com/topic/64703-solved-newb-question-about-datetime/#findComment-322648 Share on other sites More sharing options...
dbo Posted August 13, 2007 Share Posted August 13, 2007 What do you mean? Quote Link to comment https://forums.phpfreaks.com/topic/64703-solved-newb-question-about-datetime/#findComment-322653 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 i insert winner, and loser and the ID was auto but the datetime is still 0000-00-00 00:00:00 how do i record the time Quote Link to comment https://forums.phpfreaks.com/topic/64703-solved-newb-question-about-datetime/#findComment-322658 Share on other sites More sharing options...
reages Posted August 13, 2007 Share Posted August 13, 2007 your probably refering to the format. the format that you see, 0000-00-00 00:00:00, is YYYY-MM-DD HH:MM:SS. for simplicity, let's use date() (and the current local time): date ("Y-m-d H:i:s");. don't forget to insert the TIME(datetime) as string, ie: $sql = "INSERT INTO ... values (..., '" . date ("Y-m-d H:i:s") . "')" regards. Quote Link to comment https://forums.phpfreaks.com/topic/64703-solved-newb-question-about-datetime/#findComment-322806 Share on other sites More sharing options...
akitchin Posted August 13, 2007 Share Posted August 13, 2007 alternatively, you can just use MySQL's NOW() function to insert the current date and time, in the proper format: $sql = "INSERT INTO ... values (..., NOW())" Quote Link to comment https://forums.phpfreaks.com/topic/64703-solved-newb-question-about-datetime/#findComment-322808 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 thanks! Quote Link to comment https://forums.phpfreaks.com/topic/64703-solved-newb-question-about-datetime/#findComment-322819 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.