drakal30 Posted November 12, 2007 Share Posted November 12, 2007 I am storing dates in UNIX_TIME in my database, I want to select all fields in a table from the past 14 days, here is my query. $query = "SELECT DATE_SUB(DATE_FORMAT(FROM_UNIXTIME(tDate),'%Y-%m-%d'), INTERVAL 14 DAY) COUNT(id) as numrows FROM tMachIssue"; The above query errors out before the COUNT part of the string. Is my syntax wrong? Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/77065-solved-mysql-date-manipulation-help/ Share on other sites More sharing options...
Barand Posted November 12, 2007 Share Posted November 12, 2007 <?php $query = "SELECT COUNT(*) as numrows FROM tMachIssue WHERE FROM_UNIXTIME(tDate) > NOW() - INTERVAL 14 DAY"; Link to comment https://forums.phpfreaks.com/topic/77065-solved-mysql-date-manipulation-help/#findComment-390269 Share on other sites More sharing options...
drakal30 Posted November 12, 2007 Author Share Posted November 12, 2007 Awesome worked perfectly. If you have time could you explain the syntax I am properly betraying my ignorance in complicated SQL queries but what does the > do in (FROM_UNIXTIME(tDate) > NOW() - INTERVAL 14 DAY) I am guessing some kind of pointer? Link to comment https://forums.phpfreaks.com/topic/77065-solved-mysql-date-manipulation-help/#findComment-390273 Share on other sites More sharing options...
Barand Posted November 12, 2007 Share Posted November 12, 2007 FROM_UNIXTIME(tDate) converts the unix time to YYYY-MM-DD NOW() give current date NOW() - INTERVAL 14 DAY gives date 14 days ago > greater than ie WHERE the date is greater than the date 14 days ago Link to comment https://forums.phpfreaks.com/topic/77065-solved-mysql-date-manipulation-help/#findComment-390275 Share on other sites More sharing options...
drakal30 Posted November 13, 2007 Author Share Posted November 13, 2007 Oh Okay, that is simple but elegant. I thank you for your time. Makes sense to me now. Link to comment https://forums.phpfreaks.com/topic/77065-solved-mysql-date-manipulation-help/#findComment-390279 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.