SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jan 2002
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    need help with date comparison in where clause

    Hi,
    I can't seem to figure out why my where statement won't work. The field event_START is a date field (0000-00-00). I suspect that my problem has to do with type casting? of the two fields. Can somebody point me in the right direction?
    Thank you.
    Irvin.

    PHP Code:
     $month date('m'$date); 
     
    SELECT event_IDDATE_FORMAT(event_START'%d.%M.%y'), DATE_FORMAT(event_END'%d.%M.%y'), event_TOPICevent_DESCRIPTIONevent_LOCATION FROM calendar_event WHERE MONTH(( event_START ) = ".intval($month)." ORDER BY event_START 

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,323
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Code:
    i will never, never, never, never, never, never, never, never, never, never, never, never, never, never, never, never, never, never, never, never, never, never, never, never, never, never, never, never, never, never, never, never, never, never, never, never, never, never, never, never, never, never, understand why someone would prefer to read code as one long line -- SHEESH!! -- anyhow, you have improperly nested parentheses in the MONTH function
    Code:
    SELECT event_ID
         , DATE_FORMAT(event_START, '%d.%M.%y')
         , DATE_FORMAT(event_END, '%d.%M.%y')
         , event_TOPIC
         , event_DESCRIPTION
         , event_LOCATION 
      FROM calendar_event 
     WHERE MONTH( event_START ) = intval($month)
    ORDER 
        BY event_START
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Member
    Join Date
    Jan 2002
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry!
    I normally don't post code in one long line, don't know what happened.
    Anyways, I have resolved the issue by altering the where clause. THe code, which did not originate with me, uses unix time, so: "...WHERE MONTH( event_START ) = MONTH( FROM_UNIXTIME(".$date.") ) ..."
    Thanks for looking at it. I will be more careful in the future when posting code here
    Irvin.

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,323
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    i'm sorry too, i shouldn't have picked on you, but i've had to scroll and scroll and scroll once too often and something just snapped

    good job on fixing the SQL

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

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