Log in  ::  Register  ::  Not logged in

 Recent PostsRecent Posts Popular TopicsPopular Topics
 Home Search Members Calendar Who's On

 days into completed weeks only Rate Topic Display Mode Topic Options
Author
 Message
 Posted Monday, September 10, 2012 5:43 AM
 SSC-Enthusiastic Group: General Forum Members Last Login: Thursday, December 1, 2016 5:35 AM Points: 166, Visits: 562
 Hi how do i easilty convert days into weeks (obviously Days/7 will give me weeks as decimal) Problem i have is I only want to count completed weeks:ie: 20 days is 2.86 weeks. need answer to be 2 and not 3 as i get in SQL.Thanks
Post #1356671
 Posted Monday, September 10, 2012 7:14 AM
 SSCertifiable Group: General Forum Members Last Login: Sunday, January 4, 2015 7:55 AM Points: 5,333, Visits: 25,280
 Is this what you need to do ?`SELECT 2.86 /1 - 2.86 % 1 SELECT 2.16 /1 - 2.16 % 1`Result for both selects is 2.000000Note that the "%" is the modulo operator - check it out in BOL it is a powerful tool to become familiar with. If everything seems to be going well, you have obviously overlooked something. RonPlease help us, help you -before posting a question please read Before posting a performance problem please read
Post #1356711
 Posted Monday, September 10, 2012 7:36 AM
 SSC-Enthusiastic Group: General Forum Members Last Login: Thursday, December 1, 2016 5:35 AM Points: 166, Visits: 562
 Thanks, sorted the issue now.
Post #1356729
 Posted Monday, September 10, 2012 7:38 AM
 SSC Eights! Group: General Forum Members Last Login: 2 days ago @ 8:43 AM Points: 802, Visits: 4,441
 i do: `select FLOOR(2.86)`
Post #1356731
 Posted Monday, September 10, 2012 7:47 AM
 SSC Eights! Group: General Forum Members Last Login: Tuesday, November 22, 2016 1:08 AM Points: 887, Visits: 1,787
 LoosinMaMind (9/10/2012)Hi how do i easilty convert days into weeks (obviously Days/7 will give me weeks as decimal) Problem i have is I only want to count completed weeks:ie: 20 days is 2.86 weeks. need answer to be 2 and not 3 as i get in SQL.Thankswatch your data types. using integers 20/7 = 2 since SQL Server throws away the remainder when performing integer math. if you want to be absolutely certain / more precise / more explicit, i would use float or decimal with FLOOR(). For faster help in answering any problems Please read How to post data/code on a forum to get the best help - Jeff Moden for the best way to ask your question.For performance Issues see how we like them posted here: How to Post Performance Problems - Gail ShawNeed to Split some strings? Jeff Moden's DelimitedSplit8KJeff Moden's Cross tab and Pivots Part 1Jeff Moden's Cross tab and Pivots Part 2
Post #1356739
 Posted Monday, September 10, 2012 8:04 AM
 SSC-Insane Group: General Forum Members Last Login: Yesterday @ 9:26 PM Points: 23,522, Visits: 37,753
 LoosinMaMind (9/10/2012)Thanks, sorted the issue now. Proper forum etiquette would have you share your solution with others. It may help someone with a similar issue.
Post #1356755
 Posted Tuesday, September 11, 2012 7:54 AM
 Right there with Babe Group: General Forum Members Last Login: Monday, May 18, 2015 12:45 AM Points: 790, Visits: 653
 Please check if this can help you!!!select CAST(20.0/7 AS INT) + CASE WHEN (20%7) > 3 THEN 1 ELSE 0 END Regards,Mitesh OSwal+918698619998
Post #1357426

 Permissions