steveangelis Posted September 4, 2009 Share Posted September 4, 2009 I have a database with a massive group of entries in it, all with dates. What I am trying to do is get all of the dates, and this script will be run once a day, that are a year old or older. Again since this will be run consistantly the data coming out will be ever growing. My current script is this but it is not working: SELECT * FROM user WHERE lastvisit > (date("U")-315369000) Now that number, 315369000, is how many seconds i has been since a year ago but it is not working. Does anyone know why and/or how I can get it to work properly? Link to comment https://forums.phpfreaks.com/topic/173173-previous-date/ Share on other sites More sharing options...
steveangelis Posted September 4, 2009 Author Share Posted September 4, 2009 Oh and one other thing. The field lastvisit is saved as a unixtime field so all of the dates are like this: 1251726871 Link to comment https://forums.phpfreaks.com/topic/173173-previous-date/#findComment-912801 Share on other sites More sharing options...
samshel Posted September 4, 2009 Share Posted September 4, 2009 you can calculate the one year old date in PHP by $timstamp = time() - 315369000; And use that time stamp in the query $sql = "SELECT * FROM user WHERE lastvisit > '".$dt."'"; Link to comment https://forums.phpfreaks.com/topic/173173-previous-date/#findComment-912805 Share on other sites More sharing options...
kratsg Posted September 5, 2009 Share Posted September 5, 2009 If you want to be super-picky and check for leap-years and whatnot, try the following: $timestamp = strtotime("-1 year"); Note, this isn't tested, but I'm pretty sure it will work. Link to comment https://forums.phpfreaks.com/topic/173173-previous-date/#findComment-912841 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.