0

I have a datatable that saves created data as : user.createddate

Every time I add to the datatable, it saves as such for this data(timestamp) :

2016-02-02 09:10:26

What would be the best way for me to parse the timestamp, and only display results that are "x" old?

I added the following per suggestion, but it still does not parse correctly :

$cond = 'WHERE user.createddate >= DATEADD(day,-7, GETDATE())';

@Eugen helped me out in the comments. Basically, user.createddate has the entire datetime that needs to be seperated first to give me an approximation to work with in days previous, using the following code you can do as such :

$sql = "SELECT 
                * 
            FROM 
                ".$table." 
            WHERE 
                DATE(edit_date) = DATE_SUB(CURDATE(), INTERVAL 7 DAY)
            ";  
    return $sql;

I will mark you as best answer, if you post as actual answer. Thanks!

Steven
  • 687
  • 1
  • 10
  • 27

2 Answers2

0

Use MySQL functions: NOW, DATE_SUB and INTERVALL

user.createddate BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) AND NOW()
Ben Smith
  • 76
  • 5
-1

use this line : this work correctly :) echo time_elapsed_string('2016-02-02 09:10:26');

msh
  • 31
  • 3