So I have to columns one is date registered and date of expire.
For date registered I use the code below
[php]
date(“Y-m-d H:i:s”);
[/php]
My radio buttons have :
24h expiry date
2days
4days
How do you suggest I do this ?
So I have to columns one is date registered and date of expire.
For date registered I use the code below
[php]
date(“Y-m-d H:i:s”);
[/php]
My radio buttons have :
24h expiry date
2days
4days
How do you suggest I do this ?
While I think I understand what you want, clearly laying out the issue is helpful going forward along with, what you have tried to do to solve the problem.
You want to look into date modify
Here are a few ways that do the same thing.
[php]function findExpireDate( $interval )
{
$interval = intval($interval);
$regDate = date(‘Y-m-d H:i:s’);
$date = new DateTime($regDate);
// possibilities [ 24, 48, 96 ]
switch ($interval) {
case 24: // 1 day
$date->modify("+24 hours");
break;
case 48:
$date->modify("+48 hours");
break;
case 96:
$date->modify("+96 hours");
break;
default:
$date;
}
return $date->format(‘Y-m-d H:i:s’);
}
function cleanExpDate($interval, $startDate){
$allowable = [
24,
48,
96,
];
if( !in_array($interval, $allowable))
return false;
$date = new DateTime($startDate);
$date->modify("+$interval hours");
return $date->format('Y-m-d H:i:s');
}
echo “
” . date(‘Y-m-d H:i:s’) . “
”;findExpireDate: " . findExpireDate(24) . “
”;$clean
”;Date was in improper format.
”;Here’s a way in using date_diff http://php.net/manual/en/function.date-diff.php and date modify:
[php]<?php
/*
/*
” . print_r($expiriation_date, 1) . “\n”;
$exp_date = expiration_date($days_to_expiration);
/*
” . print_r($diff, 1) . “\n”;
$status = check_expiration($exp_date);
echo $status;
[/php]
Of course with a few tweaks this could refined even more where you can calculate hours and what have you.