GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Tech Display SQL record from today and past 30 days? (https://gfy.com/showthread.php?t=1359264)

Publisher Bucks 11-14-2022 08:25 PM

Display SQL record from today and past 30 days?
 
I have this code, which lets me pull records from the 'created' column for todays date & time:

Quote:

SELECT * FROM table WHERE created >= CURRENT_TIMESTAMP;
What I'd like to do is have it pull records from the last 30 +/- days AND todays date, could anyone point me in the right direction as to how to make this happen?

Just to complicate it a little, Id like it to pull based on the month, so whether a recipe was added last year, 10 years ago, etc it'll still display the data as described below.

Basically, I'm wanting a pseudo page on my recipe site that gives visitors a list of 30 recipes for breakfast, lunch and dinner (that are recent additions) which will change every day, cycling through the last 90 recipe additions (per category)s, sort of like how the old POTD pages used to work.

TIA for any help.

sarettah 11-14-2022 09:14 PM

select * from table
where created >=DATE_SUB(current_date(), INTERVAL 30 DAY)
order by created desc

That will stack all records created in the past 30 days in descending order so that the newest records are at the top of the pile.

.

Tube Ace 11-14-2022 09:17 PM

https://stackoverflow.com

You're welcome.

Publisher Bucks 11-14-2022 10:11 PM

Quote:

Originally Posted by sarettah (Post 23061857)
select * from table
where created >=DATE_SUB(current_date(), INTERVAL 30 DAY)
order by created desc

That will stack all records created in the past 30 days in descending order so that the newest records are at the top of the pile.

.

Much appreciated sir :)

I assume if I wanted to add a longer date I just change the '30'? Like, INTERVAL 30 DAY isnt a set parameter in php?

Klen 11-15-2022 07:44 AM

Quote:

Originally Posted by Tube Ace (Post 23061860)

GFY is faster :1orglaugh

Publisher Bucks 11-15-2022 04:16 PM

Quote:

Originally Posted by Klen (Post 23061998)
GFY is faster :1orglaugh

With a lot less 'fluff' and arguing thrown in too :thumbsup


All times are GMT -7. The time now is 12:41 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc