SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict sstaubin01's Avatar
    Join Date
    Nov 2000
    Location
    Ont, Canada
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to use the Date portion of Datatime in a Where clause?

    Can someone tell me how to use the date portion of a datetime column in a where clause?

    Thanks.

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ...where date_format(your_datetime_column, '%Y%m%d') = '20030612'

    Or, if you mean day, not date:
    ...where dayofmonth(your_datetime_column) = 12

  3. #3
    SitePoint Addict sstaubin01's Avatar
    Join Date
    Nov 2000
    Location
    Ont, Canada
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried that but it didn't work. The SQL statement is a join and compares to a variable that is in yyyy/mm/dd format. Here is what I coded

    ... where data_format(b.date_processed, '%Y/%m/%d') > %currdateminus183

    I will try it again and check my logic.

  4. #4
    SitePoint Addict sstaubin01's Avatar
    Join Date
    Nov 2000
    Location
    Ont, Canada
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's what I ended up doing.

    ... WHERE b.data-processed > now() - INTERVAL 183 DAY;


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
  •