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); ?> Link to comment https://forums.phpfreaks.com/topic/203177-date-not-working/ 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)); Link to comment https://forums.phpfreaks.com/topic/203177-date-not-working/#findComment-1064530 Share on other sites More sharing options...
liamloveslearning Posted May 28, 2010 Author Share Posted May 28, 2010 Doesnt seem to work, strange Link to comment https://forums.phpfreaks.com/topic/203177-date-not-working/#findComment-1064538 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; ?>" /> Link to comment https://forums.phpfreaks.com/topic/203177-date-not-working/#findComment-1064539 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"))); Link to comment https://forums.phpfreaks.com/topic/203177-date-not-working/#findComment-1064544 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); ?> Link to comment https://forums.phpfreaks.com/topic/203177-date-not-working/#findComment-1064556 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? Link to comment https://forums.phpfreaks.com/topic/203177-date-not-working/#findComment-1064558 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 Link to comment https://forums.phpfreaks.com/topic/203177-date-not-working/#findComment-1064560 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); Link to comment https://forums.phpfreaks.com/topic/203177-date-not-working/#findComment-1064561 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(); ?> Link to comment https://forums.phpfreaks.com/topic/203177-date-not-working/#findComment-1064567 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 Link to comment https://forums.phpfreaks.com/topic/203177-date-not-working/#findComment-1064571 Share on other sites More sharing options...
liamloveslearning Posted May 28, 2010 Author Share Posted May 28, 2010 Thanks ChaosKnight! Link to comment https://forums.phpfreaks.com/topic/203177-date-not-working/#findComment-1064577 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.