$php_mysql$ Posted August 18, 2011 Share Posted August 18, 2011 how do i add 30 days from current date? $newdate = date("D, j F, Y", $date); displays Thu, 18 August, 2011 now with a new variable how do i display a date 30 days from Thu, 18 August, 2011 which would be September something? i tried $newdate = date("D, j F, Y", $date); $newdate2 = date("D, j F, Y", time() + $date); but it display Mon, 26 February, 1917 Link to comment https://forums.phpfreaks.com/topic/245094-addition-to-date/ Share on other sites More sharing options...
criostage Posted August 18, 2011 Share Posted August 18, 2011 try <?php echo 'Now: '. date('Y-m-d') ."\n"; echo 'in 30 days: '. date('Y-m-d', strtotime('+30 days')) ."<br>"; // Or echo 'in 30 days: '. date('Y-m-d', time() + 2592000) ."<br>"; ?> my output was: Now: 2011-08-18 in 30 days: 2011-09-17 in 30 days: 2011-09-17 More Information on the functions: TIME() - http://php.net/manual/en/function.time.php strtotime() - http://php.net/manual/en/function.strtotime.php Link to comment https://forums.phpfreaks.com/topic/245094-addition-to-date/#findComment-1258922 Share on other sites More sharing options...
$php_mysql$ Posted August 18, 2011 Author Share Posted August 18, 2011 thanks soo much \m/ Link to comment https://forums.phpfreaks.com/topic/245094-addition-to-date/#findComment-1258923 Share on other sites More sharing options...
$php_mysql$ Posted August 18, 2011 Author Share Posted August 18, 2011 oh one issue, i want ti compare the date with $newdate which comes from database $newdate = date("D, j F, Y", $date); //compare this $addtiondate = date("D, j F, Y", strtotime('+30 days')); // to this how can that be done here? Link to comment https://forums.phpfreaks.com/topic/245094-addition-to-date/#findComment-1258925 Share on other sites More sharing options...
voip03 Posted August 18, 2011 Share Posted August 18, 2011 <? $newdate = date("D, j F, Y", $date); //compare this $addtiondate = date("D, j F, Y", strtotime('+30 days')); // to this if(strtotime($addtiondate) > strtotime($newdate)){ // bla bla } ?> Link to comment https://forums.phpfreaks.com/topic/245094-addition-to-date/#findComment-1258935 Share on other sites More sharing options...
$php_mysql$ Posted August 18, 2011 Author Share Posted August 18, 2011 <? $newdate = date("D, j F, Y", $date); //compare this $addtiondate = date("D, j F, Y", strtotime('+30 days')); // to this if(strtotime($addtiondate) > strtotime($newdate)){ // bla bla } ?> thanks but result show just 1 where as 30 days from today would be Sat, 17 September, 2011 i did this $newdate = date("D, j F, Y", $date); //compare this $addtiondate = date("D, j F, Y", strtotime('+30 days')); // to this $addition = strtotime($addtiondate) > strtotime($newdate); echo $addition ; Link to comment https://forums.phpfreaks.com/topic/245094-addition-to-date/#findComment-1258941 Share on other sites More sharing options...
$php_mysql$ Posted August 18, 2011 Author Share Posted August 18, 2011 any one? Link to comment https://forums.phpfreaks.com/topic/245094-addition-to-date/#findComment-1259045 Share on other sites More sharing options...
PFMaBiSmAd Posted August 18, 2011 Share Posted August 18, 2011 Why are you doing multiple conversions on both values to compare dates? If your dates are stored in your database as either a mysql DATE, DATETIME, or TIMESTAMP data type, you can do greater-than/less-than comparisons directly on the values, as someone explained in one of your previous threads, provided both values being compared are in the same format. What exactly are you trying to accomplish by comparing dates? Link to comment https://forums.phpfreaks.com/topic/245094-addition-to-date/#findComment-1259052 Share on other sites More sharing options...
TeNDoLLA Posted August 18, 2011 Share Posted August 18, 2011 Not sure what you trying to achieve with this line $addition = strtotime($addtiondate) > strtotime($newdate); but $addition variable will have a boolean value based on the condition. In this case it will be "true" since the $additiondate is greater than $newdate. Link to comment https://forums.phpfreaks.com/topic/245094-addition-to-date/#findComment-1259055 Share on other sites More sharing options...
$php_mysql$ Posted August 18, 2011 Author Share Posted August 18, 2011 no this time is not stored in mysql DATETIME format, stored the time using time() so the some without conversion shows something like 1234567 etc, $newdate = date("D, j F, Y", $date); //this line converts the time to Thu, 18 August, 2011 format so what im trying is getting 30 days from $newdate which prints the result as Thu, 18 August, 2011 and i want Sat, 17 September, 2011 Link to comment https://forums.phpfreaks.com/topic/245094-addition-to-date/#findComment-1259066 Share on other sites More sharing options...
TeNDoLLA Posted August 18, 2011 Share Posted August 18, 2011 $newdate = date("D, j F, Y", strtotime('+30 days', $date)); echo $newdate; ... assuming $date is a timestamp. Link to comment https://forums.phpfreaks.com/topic/245094-addition-to-date/#findComment-1259084 Share on other sites More sharing options...
$php_mysql$ Posted August 18, 2011 Author Share Posted August 18, 2011 wow i did try something similar earlier but dunno kept getting parse error :-) thanks soo much again. \m/ Link to comment https://forums.phpfreaks.com/topic/245094-addition-to-date/#findComment-1259087 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.