leeming Posted July 13, 2006 Share Posted July 13, 2006 i feel stupid asking this, but i seem to be in one of them state of minds where you cant think of the little simple things...but how do i go about adding say 31 days to a date in this format: date("Y-m-d") Link to comment https://forums.phpfreaks.com/topic/14541-i-feel-so-stupid-asking-a-noob-question-about-date/ Share on other sites More sharing options...
Barand Posted July 14, 2006 Share Posted July 14, 2006 $date = '2006-07-14';$date31 = date ('Y-m-d', strtotime("+31 days $date")); Link to comment https://forums.phpfreaks.com/topic/14541-i-feel-so-stupid-asking-a-noob-question-about-date/#findComment-57659 Share on other sites More sharing options...
kenrbnsn Posted July 14, 2006 Share Posted July 14, 2006 Try this:[code]<?php$dt = date('Y-m-d');$dt31 = date('Y-m-d,strtotime($dt . ' + 31 days'));echo $dt . '<br>' . $dt31;?>[/code]or[code]<?php$one_day = 86400; // number of seconds in a day$dt = '2006-07-20'; //arbitrary date$dt31 = date('Y-m-d',strtotime($dt)+(86400 * 31)));echo $dt . '<br>' . $dt31;?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/14541-i-feel-so-stupid-asking-a-noob-question-about-date/#findComment-57661 Share on other sites More sharing options...
leeming Posted July 14, 2006 Author Share Posted July 14, 2006 thanks.. i had justed started looking thru some SQL manuals. and ended up with this[code]CURDATE() + INTERVAL ".$daynums." DAY[/code]it worked for the INSERT but not an UPDATE.. will replace it with the above code. thanks Link to comment https://forums.phpfreaks.com/topic/14541-i-feel-so-stupid-asking-a-noob-question-about-date/#findComment-57666 Share on other sites More sharing options...
kenrbnsn Posted July 14, 2006 Share Posted July 14, 2006 That should work with either Insert or Update. Can you post the code that didn't work?Ken Link to comment https://forums.phpfreaks.com/topic/14541-i-feel-so-stupid-asking-a-noob-question-about-date/#findComment-57668 Share on other sites More sharing options...
leeming Posted July 14, 2006 Author Share Posted July 14, 2006 trying to get this to work, bit over tired, and cant think stright...[code]"update Premium set date_renew = ".date ('Y-m-d', strtotime("+31 days ".`date_renew`.""))." WHERE user='{$_POST[user]}'"[/code]but the curdate code i tried before, i couldnt get to work.. some thing like..[code]"update Premium set date_renew =`date_renew` + (CURDATE() + INTERVAL ".$daynums." DAY) WHERE user='{$_POST[user]}'""[/code]~~ $daynums been a value of either 31 (month) or 365 (year)~~edit 2..fixed![code]"update Premium set date_renew =DATE_ADD(`date_renew`, INTERVAL $daynums DAY) WHERE user='{$_POST[user]}'"[/code] Link to comment https://forums.phpfreaks.com/topic/14541-i-feel-so-stupid-asking-a-noob-question-about-date/#findComment-57673 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.