Jump to content

retrieving mysql information using yesterdays date


phpmikey

Recommended Posts

hi, i am using the following code to retrieve information for todays date:

<?php
			$query =  "select * from customer where DATE (date) = DATE(NOW())";
			$result = @mysql_query($query, $connection) 
			or die ("Unable to perform query.<br />$query<br/>");

			$num_rows = mysql_num_rows($result); 	
			echo "$num_rows"; 
			?>

 

i cant seem to find any code to extract information from yesterdays date. can you help please?

 

The @ is supressing any useful errors.  Try this and see what the error says, (my bet is the DATE being used a column name).

 

$result = mysql_query($query, $connection) or trigger_error("MySQL Query Failed: " . mysql_error());

 

See what the shows ya.

no the code i posted is fully working code and retrieves the information i need data entered for todays date. the question was how can i adapt this to retrieve information for yesterdays date.

 

for example show all records where date = yesterdays date.

perhaps this snippet may point you the way...

 

WHERE date = DATE_ADD(CURDATE(), INTERVAL -1 DAY)

 

EDIT!

 

that did work when i inserted my saved date value.

 

$query =  "select * from customer WHERE date (date) = DATE_ADD(CURDATE(), INTERVAL -1 DAY)";

 

thanks very much for your help  8)

 

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.