I’m using time() to store date in the database.
I have some kind of advertising web site.
Users submit their ads and number of the days they want their ads to be shown for example:
title : ad title….
duration : 20 days
creation date : time() (I get the creation date by time() when I’m
submitting this ad on the database. )
I need to calculate expiration date for each ad on epoch format.
exp_date = creation date + 20 days ; /// this line is hypothetical , i need correct way to calculate exp_Date
sql->set(experation date = exp_date);
Also I need to know how much time is left to the exp date in days and hours and minutes and show it on the page.
$current time = time();
$remaining_time = $current time - $exp date ; //this line is hypothetical , i need correct way to calculate remaining_time
echo 'remaining time : '.$remaining_time ;
At last I don’t want to show expired ads (I’m not sure the best way to do this is to calculate time when I’m showing the ads maybe I could somehow automatically disable ads status after 20 days?)
current date = time();
if (ads experation date > current date ) // this line is hypothetical , i need to calculate this
sql->update ('set ads status= 0');
echo 'this ad has been expires ';
exit;
To calculate the expiration date:
To calculate the time left, you should do something like
$daysLeft,$hoursLeft,$minutesLeftand$secondsare the values that you want