Jump to content

Recommended Posts

Hi Every Body

I Am An Intermediate in php and mysql

 

i am creating a stock exchange site using php and mysql

 

now the prob is that i have to get last 5 day's entries from today from database

 

 

Can AnyBody Help me......

 

[move]Pls It's Very Impppppppp...........[/move]

 

Since you didn't supply how you stored the date/time, I'm going to assume it is in yyyy/mm/dd format.

 

So try this

<?php

$five_days_ago = date("Y-m-d", strtotime("- 5 DAY"));
$query = mysql_query("SELECT * FROM table WHERE `date` < $five_days_ago")or die(mysql_error());

?>

If the date is stored in the database as a DATETIME or DATE type, you can easily retrieve your selected records by doing something like this with your query alone:

SELECT * 
FROM myTable
WHERE date_field >= (CURDATE() - INTERVAL 5 DAY);

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.