Ryan Bayne
asked on
Adding days to a date and comparing dates within argument
Hi
I need to check the datetime I have in my DB (MSSQL) against the current datetime. If the current datetime is 7 days after the DB stored datetime then true.
if($now >= $wcpastdate){
}
else { current datetime is not 7 days after the DB datetime so do something different here }
So I was thinking I would have to increase the stored date by 7 and if its still more than the current date I dont have to do anything otherwise I need to reset the datetime in database.
Thanks for any solutions
I need to check the datetime I have in my DB (MSSQL) against the current datetime. If the current datetime is 7 days after the DB stored datetime then true.
if($now >= $wcpastdate){
}
else { current datetime is not 7 days after the DB datetime so do something different here }
So I was thinking I would have to increase the stored date by 7 and if its still more than the current date I dont have to do anything otherwise I need to reset the datetime in database.
Thanks for any solutions
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Nice, but for my use I think it would be minus.
So basically take 7 away from the current days ($now) and if it is still AFTER the past date retrieved from the datebase ($wcpastdate) then the past date is older than 7 days and needs to be replaced else if ($now) ends up a date before that date than it skips the first part of if statement.
$now = strtotime('-7 days', date('d-m-y'));
//var_dump($now, $wcpastdate); exit;
//Check if $now is 6 days 23 hours and 59 minutes more than datetime in weeklycar table
if($now >= strtotime($wcpastdate)){
$sql="DELETE FROM weeklycar WHERE stockID = '$wcpastid'";
$deleterow=mssql_query($sq l);
if (!$deleterow) {die('Query execution problem delete the current car of the week');}
Thats great thanks
So basically take 7 away from the current days ($now) and if it is still AFTER the past date retrieved from the datebase ($wcpastdate) then the past date is older than 7 days and needs to be replaced else if ($now) ends up a date before that date than it skips the first part of if statement.
$now = strtotime('-7 days', date('d-m-y'));
//var_dump($now, $wcpastdate); exit;
//Check if $now is 6 days 23 hours and 59 minutes more than datetime in weeklycar table
if($now >= strtotime($wcpastdate)){
$sql="DELETE FROM weeklycar WHERE stockID = '$wcpastid'";
$deleterow=mssql_query($sq
if (!$deleterow) {die('Query execution problem delete the current car of the week');}
Thats great thanks
ASKER
Aw got an error
A non well formed numeric value encountered in C:\AppServ\www\cars\inc\we eklycar.ph p on line 16
$now = strtotime('-7 days', date('d-m-y'));
A non well formed numeric value encountered in C:\AppServ\www\cars\inc\we
$now = strtotime('-7 days', date('d-m-y'));
sorry my mistake, it needs to be a unix date stamp.
$now = strtotime('-7 days', date('U'));
$now = strtotime('-7 days', date('U'));
ASKER
Thanks
SELECT TOP 1 DATEADD(day, 7, yourdatetimefield) AS dbdate from yourtable where dbdate>GETDATE()