Asnexplore
Asnexplore

Reputation: 363

Need to know if a given date has expired or not

I need to know how can i get to know in php that whether a given date is expired or not? I need to show the status of the same in a package manager where I need to know whether the package is active or expired. I have 2 fields in mysql table called start_date and expiry_date.

I need to know how can I subtract the expiry_date from star_date and get the value and then check whether that expiry_date is expired or yet to expire.

Please help me.

Upvotes: 0

Views: 5457

Answers (2)

SamHuckaby
SamHuckaby

Reputation: 1162

Okay, I'm going to make a few assumptions so that my answer can be more clear.

If your expiry_date is the date that the package expires, you can use php to check whether it is a date in the future or not like so.

$exp_date = strtotime($expiry_date);

if(time() > $exp_date) // your package has expired.

Upvotes: 3

jtheman
jtheman

Reputation: 7491

Try DATEDIFF in MySQL

SELECT DATEDIFF(expiry_date,start_date) AS difference FROM packages...

Or in PHP you could iterate through the answers and select something like:

 $curr_date = date('Y-m-d'); // or your date format

// loop

if ($row['start_date'] <= $curr_date && $row['expiry_date'] > $curr_date){
  // post is active
}
elseif ($row['expiry_date'] > $curr_date)
{
   // post expired
}

Upvotes: 1

Related Questions