pocobueno1388 Posted October 1, 2006 Share Posted October 1, 2006 I am trying to add the current date + 7 days to the database whenever a user clicks a submit button, why won't this work?[code]$next_breed = date ('Y/m/d', strtotime ("U +7 days"));mysql_query("UPDATE dog SET last_bred='$next_bred' WHERE dogID='$row3[dogID]'");[/code]It does absolutely nothing to the 0000-00-00 date in the database. Link to comment https://forums.phpfreaks.com/topic/22646-quick-easy-date-question/ Share on other sites More sharing options...
JasonLewis Posted October 1, 2006 Share Posted October 1, 2006 you have to use the mktime() function.try this:[code]$next_breed = date('Y/m/d', mktime(0, 0, 0, date('m'), date('d')+7, date('Y'));[/code]i aint sure though, i havnt used it very often. Link to comment https://forums.phpfreaks.com/topic/22646-quick-easy-date-question/#findComment-101726 Share on other sites More sharing options...
Barand Posted October 1, 2006 Share Posted October 1, 2006 Typo!$next_br[color=red]ee[/color]d = date ('Y/m/d', strtotime ("U +7 days"));mysql_query("UPDATE dog SET last_bred='$next_br[color=red]e[/color]d' WHERE dogID='$row3[dogID]'");ps Best to store date as "Y-m-d", mysql's native format. Link to comment https://forums.phpfreaks.com/topic/22646-quick-easy-date-question/#findComment-101740 Share on other sites More sharing options...
Daniel0 Posted October 1, 2006 Share Posted October 1, 2006 [quote author=Barand link=topic=110132.msg444609#msg444609 date=1159694357]ps Best to store date as "Y-m-d", mysql's native format.[/quote]Best to store date as a UNIX timestamp: [url=http://php.net/time]time() Link to comment https://forums.phpfreaks.com/topic/22646-quick-easy-date-question/#findComment-101745 Share on other sites More sharing options...
Barand Posted October 1, 2006 Share Posted October 1, 2006 So long as when you want to use MySQL's date/time functions you don't mind the additiona overhead of always converting it with FROM_UNIXTIME() first. e.g.[code]SELECT DATE_FORMAT(FROM_UNIXTIME(newtime), '%m-%d-%Y %H:%i') FROM tablename[/code]And you can always tell any users who might be executing their own SQL queries on the database that, with experience, they will soon get to recognise 1157137200 as '2006-09-01 20:00' without any problem at all. Link to comment https://forums.phpfreaks.com/topic/22646-quick-easy-date-question/#findComment-101772 Share on other sites More sharing options...
Daniel0 Posted October 1, 2006 Share Posted October 1, 2006 Just [code]mysql_query("INSERT INTO table (the_time) VALUES(".time().");");[/code] Link to comment https://forums.phpfreaks.com/topic/22646-quick-easy-date-question/#findComment-101843 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.