I have a date in format "Y-m-d H:i:s"
example: 2003-05-04 21:05:29

and now I have to write a function that returns the DIFFERENCE between the date stored in database and the date NOW....

if it is greater than 1 day it returns NUMBER OF DAYS
if it is less than 1 day and greater than 1 hour it returns NUMBER OF HOURS
if it is less than 1 hour and greater than 1 minute it returns NUMBER OF MINUTES
if it is less than 1 minute and greater than 1 second it returns NUMBER OF SECONDS
if it is less than 1 second it returnes 'NONE'

    Well, you could consider using strtotime(), then find the difference with time()

    After that, it would just be a case of using some arithmetic to parse it the way you want.

      I have done as You said....
      and now I have the difference in timestamp.......

      but how to change it into days,hours,minutes,seconds

        Hi,

        You use the date() funtcion,
        Then make $days $hours $minutes $seconds. You can then check wether $days == 0 or not.

        $days = date(d, $timestampDifference); //or something like this.

        J.

          Write a Reply...