Jump to content

[SOLVED] mySql date manipulation help


drakal30

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.