If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Pulling weekdays

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-23-12, 12:11
nolph nolph is offline
Registered User
 
Join Date: Jan 2012
Posts: 4
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
Reply With Quote
  #2 (permalink)  
Old 01-23-12, 13:15
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 620
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
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
  #3 (permalink)  
Old 01-23-12, 14:49
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
instead of DATE_FORMAT, i believe you want FROM_UNIXTIME

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 01-23-12, 14:53
nolph nolph is offline
Registered User
 
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.
Reply With Quote
  #5 (permalink)  
Old 01-23-12, 14:59
nolph nolph is offline
Registered User
 
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.
Reply With Quote
  #6 (permalink)  
Old 01-23-12, 15:33
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
change this --
Code:
AND DATE_FORMAT(timestamp, '%a') NOT IN ('Sat','Sun')
to this --
Code:
AND FROM_UNIXTIME(timestamp, '%a') NOT IN ('Sat','Sun')
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 01-23-12, 17:09
nolph nolph is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On