Jump to content

How To Get Last 5 Day's Data Using PHP & MYSQL


rohit_purohit

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);

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.