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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.