Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2012
    Posts
    4

    Unanswered: Pulling weekdays

    Hello,
    ive ran into a snag with my sql code and need a hand if possible.

    Code:
    Select distinct from_unixtime(timestamp, '%Y-%m-%d') from netagent.os_table 
    where from_unixtime(timestamp, '%Y-%m-%d') > CURDATE() - INTERVAL 40 DAY 
    order by from_unixtime(timestamp, '%Y-%m-%d')
    right now it pulls the dates specified. What i need to do is exclude the weekends. How would i do that?

    If anyone could help that would be great. Thanks

  2. #2
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    Using the DATE_FORMAT function it can return the Day of the week %a. Using this we can have:

    Select distinct from_unixtime(timestamp, '%Y-%m-%d') from netagent.os_table
    where from_unixtime(timestamp, '%Y-%m-%d') > CURDATE() - INTERVAL 40 DAY
    AND DATE_FORMAT(timestamp, '%a') NOT IN ('Sat','Sun')
    order by from_unixtime(timestamp, '%Y-%m-%d')
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    instead of DATE_FORMAT, i believe you want FROM_UNIXTIME

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Jan 2012
    Posts
    4
    Tried that code and nothing was outputted to the window... There are no words in the dates stored in the DB. its all numbers.

  5. #5
    Join Date
    Jan 2012
    Posts
    4
    Quote Originally Posted by r937 View Post
    instead of DATE_FORMAT, i believe you want FROM_UNIXTIME

    What would i have to change in the code? im not sure what to do.

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    change this --
    Code:
    AND DATE_FORMAT(timestamp, '%a') NOT IN ('Sat','Sun')
    to this --
    Code:
    AND FROM_UNIXTIME(timestamp, '%a') NOT IN ('Sat','Sun')
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  7. #7
    Join Date
    Jan 2012
    Posts
    4
    Quote Originally Posted by r937 View Post
    change this --
    Code:
    AND DATE_FORMAT(timestamp, '%a') NOT IN ('Sat','Sun')
    to this --
    Code:
    AND FROM_UNIXTIME(timestamp, '%a') NOT IN ('Sat','Sun')
    That worked like a charm. Thank you

Posting Permissions

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