php date and timestamp subtraction

Discussion in 'Software' started by JJJIrish05, Jan 5, 2010.

  1. JJJIrish05

    JJJIrish05 Sergeant

    So I need to query a mysql database and get a timestamp and a date out of it. I have to subtract the timestamp from the date with php to find the number of days between the 2. Query is easy, but how do I subtract the 2?

    Timestamp: 2009-12-23 11:49:56
    Date: 2010-01-06

    Just doing $data['date']-$data['timestamp'] obviously doesn't work. So how do I have to mod them to do it?
     
  2. JJJIrish05

    JJJIrish05 Sergeant

    Figured it out. I used strtotime to convert the strings from the query to time in seconds. Then subtracted the 2. Then divided it by 86400 (number of seconds in a day). Then type cast it to int to truncate it and just get the number of full days between the 2 dates.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds