-3

Possible Duplicate:
PHP:find day difference between two date(“YmdHis”) reture

What I want to do is to get day from database, current date. And check if difference between them > 1 day:

$curdate= date("Y-m-d H:i:s");

$dbdate is value stored in datetime format in db.

$dif=$curdate-dbdate;

How to check if $dif>1 day ??

Community
  • 1
  • 1
heron
  • 3,611
  • 25
  • 80
  • 148

2 Answers2

3

Assuming the stored date is expressed in the same time zone as the server, you can convert it to a timestamp using strtotime, and compare it to strtotime("-1 day"):

if (strtotime($dbdate) < strtotime("-1 day"))
  frobnicate();
Victor Nicollet
  • 24,361
  • 4
  • 58
  • 89
0

You can get just the day from each date.

$day = intval($curdate= date("d"));

This will get the day as an in. Do the same for the time of the data base and you get two integer representing the day. Using that you can calculate how many days have pass.

Beware that the last line should look like this:

$dif = abs($curdate-$dbdate);
petermlm
  • 930
  • 4
  • 12
  • 27