Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

php alternative to Now() -7

Community Beginner ,
Mar 06, 2007 Mar 06, 2007
Hi, im developping a blog site. On this site every blog post gets a date when it gets posted in the formart of date("Y-m-d H:i:s"). On one of my pages on the frontend of the site i want to display only posts that are 7 days old or younger. I am following a Lynda.com course which describes this whole thing, but it is for ASP and i am using PHP/MySQL. In the course a new recordset gets created which looks like this:

SELECT intPostID, vchPostTitle, intPostBy, dtePostDate, intCatID, txtPostContent, tblusers.vchNickName
FROM tblblog, tblusers
WHERE intPostShow = 1 AND tblBlog.intPostBy = tblUsers.intUserID AND tblblog.dtePostDate > MMColParam
ORDER BY dtePostDate DESC

In the variables window a new variable gets created, which looks like this:
Name:MMColParam
Type:Date
Default Vaue: 2003-01-01
Run Time Value: Now() -7

The Now() -7 function is a VBscript function, so i need something that can do the same, but using PHP. Plz help.
TOPICS
Server side applications
561
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 06, 2007 Mar 06, 2007
metalllus wrote:
> On one of my pages on the
> frontend of the site i want to display only posts that are 7 days old or
> younger.

Do it with your SQL query.

> SELECT intPostID, vchPostTitle, intPostBy, dtePostDate, intCatID,
> txtPostContent, tblusers.vchNickName
> FROM tblblog, tblusers
> WHERE intPostShow = 1 AND tblBlog.intPostBy = tblUsers.intUserID AND
> tblblog.dtePostDate > MMColParam
> ORDER BY dtePostDate DESC

Change it to this:

SELECT intPostID, vchPostTitle, intPostBy, dtePostDate, intCatID,
txtPostContent, tblusers.vchNickName
FROM tblblog, tblusers
WHERE intPostShow = 1 AND tblBlog.intPostBy = tblUsers.intUserID AND
tblblog.dtePostDate >= DATE_SUB(NOW(), INTERVAL 7 DAY)
ORDER BY dtePostDate DESC

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 06, 2007 Mar 06, 2007
it works just fine, thx a lot.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 06, 2007 Mar 06, 2007
LATEST
metalllus wrote:
> it works just fine, thx a lot.

Glad to be of help.

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines