...

a better way of expressing this.....

sweenster
11-08-2002, 06:12 PM
i have the following block of php code to read and extract all databse entries marked with todays date on them:


$thedate = date("Ymd");
$query = "SELECT *,DATE_FORMAT(date,'%Y%m%d') AS fdate, FROM stats";
if ($mysql_result = mysql_query($query, $linkdb)) {
if (ExecuteQuery($linkdb, $result, $query)) {
while ($row = NextRow($result)) {
if ($row['fdate'] == $thedate) {
#print out the record etc.
}
}
}
}


i'm looking for a way i can do this in one go in the SQL query string, without having to go through all of them.
the field 'date' is a 14digit timestamp.

Spookster
11-08-2002, 09:09 PM
Why don't you just select the records with todays date instead of pulling all the records?

$query = "SELECT * FROM stats WHERE datefield = '$todaysDate'";

sweenster
11-08-2002, 11:54 PM
ah, yes.
I WOULD do that but I cant.

The date field is defined as (say) 20021109hhmmss
and the only SELECT statement I can fire at it is:

SELECT * FROM stats WHERE date = "20021109"
i can't define the time, and that essentially is where the problem lies as I want to select every record for todays date.

Spookster
11-09-2002, 12:14 AM
Ok so then use the LIKE command:

$query = "SELECT * FROM stats WHERE datefield LIKE '$todaysDate'%";

mordred
11-09-2002, 10:04 PM
Or

SELECT * FROM stats WHERE TO_DAYS(date) = TO_DAYS("20021109")

if you have to compare against a certain timestamp; if you need to get the rows of today's date, then use

SELECT * FROM stats WHERE TO_DAYS(date) = TO_DAYS(CURDATE())



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum