Jump to content

display result of last 30 days


php_begins

Recommended Posts

I have a post table that has some of these fields:

i want to query the number of posts that happened in the last 30 days and display the date.i.e display posts that happened on each date and the also display the date.

EG:

            NO  DATE

POSTS 10  1/9/2011

POSTS  20  31/8/2011

 

i know i can do a select postid and then do a mysql_num_rows to get the number of posts. But I am not sure how to get the result of last 30 days and display that date. Here is my table structure

postid  username userid   title             dateline

1            test                3        member          1186945212

3            tester              5          JM                  1187106827

Link to comment
https://forums.phpfreaks.com/topic/246199-display-result-of-last-30-days/
Share on other sites

exactly.

 

also, i should point out a tiny flaw in my code.  since you're using a unix timestamp, the "30 days ago" is based on 30 days before the current second of today.  so things that happened on the day 30 days ago but before the current time won't be found.

 

so really, instead of:

 

strtotime("-30 days"); // which is 30 days before the current second of the current day

 

you should use:

 

strtotime("-30 days", strtotime(date("Y-m-d")) );  // which is 30 days before this morning at midnight

 

hope that helps!

 

FYI, next time it might be better to just use the "date" column type in MySQL in the first place which formats all your deads in human readable "YYYY-MM-DD" format and allows mysql to do some pretty easy calculations as well.

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.