Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Location
    Scotland
    Posts
    407
    Thanks
    0
    Thanked 0 Times in 0 Posts

    a better way of expressing this.....

    i have the following block of php code to read and extract all databse entries marked with todays date on them:

    PHP Code:
    $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.
    My body's a temple... and like those ancient Greek ones it's a ruin
    sweenster.co.uk

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Why don't you just select the records with todays date instead of pulling all the records?

    $query = "SELECT * FROM stats WHERE datefield = '$todaysDate'";
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #3
    Regular Coder
    Join Date
    Sep 2002
    Location
    Scotland
    Posts
    407
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    My body's a temple... and like those ancient Greek ones it's a ruin
    sweenster.co.uk

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Ok so then use the LIKE command:

    $query = "SELECT * FROM stats WHERE datefield LIKE '$todaysDate'%";
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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())
    Last edited by mordred; 11-09-2002 at 10:06 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •