davidcriniti Posted July 18, 2014 Share Posted July 18, 2014 Hi everyone, My googling seems to have found an way to add x days to the current date, and I'm sure that finding x days from a date pulled from my database must be pretty similar, but I just can't seem to get it working. My task involves teachers setting notifications which are displayed for a number of days designated by the teacher. So when the teacher creates the notiication, the `notificatin_date` field is updated with the timestamp. The `notification_duration` field is an integer between 1 and 21. I can get this info out of the database without problem: $notification_set = date('Y-m-d', strtotime($notification['notification_date'])); $notification_duration = $notification['notification_duration']; echo $notification_duration . "<br/>"; echo $notification_set . "<br/>"; However, when I try and add the duration to the date when the notification was set, to echo the expiry date, I run in to problems. This is what I've got at the current time, but I'm obviously not 'adding' $notification_duration and $notification_set correctly in the first line below, which is causing all my problems. Any help is much appreciated. $expiration_date = $notification_set + strtotime($notification_duration . "days"); if ($expiration_date> date) { echo "Your notification will expire on "; } else if ($expiration_date < date) { echo "Your notification expired on "; } else echo "Your notification expires today "; echo date('jS', strtotime($expiration_date)); echo " of "; echo date('F', strtotime($expiration_date)); echo ", "; echo date('Y', strtotime($expiration_date)); Thanks for your time, Dave Link to comment https://forums.phpfreaks.com/topic/289968-expiration-date/ Share on other sites More sharing options...
kicken Posted July 18, 2014 Share Posted July 18, 2014 SELECT notification_date as notification_date, notification_date + INTERVAL notification_duration DAY as notification_expires FROM teacher_notificationsNo need to do any kind of date math in PHP, just let MySQL handle it. Link to comment https://forums.phpfreaks.com/topic/289968-expiration-date/#findComment-1485622 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.