liamloveslearning Posted May 28, 2010 Share Posted May 28, 2010 Hi everyone, I have this snippet of code which i need to add 7 days too <?php echo $row_last_picture_date['startdate']; ?> the above code outputs 28/05/2010 Im trying to add 7 days using the code below but it outputs 07/01/1970, can anydbody see why? <?php $today = $row_last_picture_date['startdate']; $est = strtotime('+7 day', strtotime($today)); print date('d/m/Y', $est); ?> Quote Link to comment Share on other sites More sharing options...
ChaosKnight Posted May 28, 2010 Share Posted May 28, 2010 Try this: $picturedate = $row_last_picture_date['startdate']; $date = date(“Y m d”,strtotime(“+7 days”,$picturedate)); Quote Link to comment Share on other sites More sharing options...
liamloveslearning Posted May 28, 2010 Author Share Posted May 28, 2010 Doesnt seem to work, strange Quote Link to comment Share on other sites More sharing options...
liamloveslearning Posted May 28, 2010 Author Share Posted May 28, 2010 The current code I have works to an extent, it adds 7 days, but it adds it to the current date and not my DB date <?php $curdate = $row_last_picture_date['user_picture_date']; $plus7 = date("Y-m-d",mktime(0,0,0,date("m"),date("d")+7,date("Y"))); echo $plus7; ?>" /> Quote Link to comment Share on other sites More sharing options...
liamloveslearning Posted May 28, 2010 Author Share Posted May 28, 2010 How can I add my variable to this value? I see its just adding 7 days to the current date now, $plus7 = date("Y-m-d",mktime(0,0,0,date("m"),date("d")+7,date("Y"))); Quote Link to comment Share on other sites More sharing options...
liamloveslearning Posted May 28, 2010 Author Share Posted May 28, 2010 Ive just tried this, i think it makes sense but its still incorrect! can anybody see why? <?php $today = $row_last_picture_date['user_picture_date']; $est = strtotime('+7 day', strtotime($today)); print date('d/m/Y', $est); ?> Quote Link to comment Share on other sites More sharing options...
ChaosKnight Posted May 28, 2010 Share Posted May 28, 2010 Have you tried this?: <?php $today = $row_last_picture_date['user_picture_date']; $est = date(“d/m/Y”,strtotime(“+7 days”,$today)); print date('d/m/Y', $est); ?> The code you had a problem with adds 7 days to the date in the db, do you want code that adds 7 days to the current date? Quote Link to comment Share on other sites More sharing options...
liamloveslearning Posted May 28, 2010 Author Share Posted May 28, 2010 Just tried it and it prints out 01/01/1970, Its not even adding 7 days now Quote Link to comment Share on other sites More sharing options...
ChaosKnight Posted May 28, 2010 Share Posted May 28, 2010 What about this: function addDate($date,$day)//add days { $sum = strtotime(date("Y-m-d", strtotime("$date")) . " +$day days"); $dateTo=date('Y-m-d',$sum); return $dateTo; } then you can call it like this: $est = addDate($today,7); Quote Link to comment Share on other sites More sharing options...
liamloveslearning Posted May 28, 2010 Author Share Posted May 28, 2010 Got it working! it was my Table data type was set incorrectly! Thanks for your help tho, Is it possible to set a default table value as current date? eg <?php echo date(); ?> Quote Link to comment Share on other sites More sharing options...
ChaosKnight Posted May 28, 2010 Share Posted May 28, 2010 In your SQL? If that's the case, then you can set the table type as a timestamp and the default value as 0000-00-00 for yyyy-mm-dd, you can also do the time 0000-00-00 00:00:00 Quote Link to comment Share on other sites More sharing options...
liamloveslearning Posted May 28, 2010 Author Share Posted May 28, 2010 Thanks ChaosKnight! Quote Link to comment 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.