Thomas Moore
Thomas Moore

Reputation: 981

SQL converting number of days to weeks

I have a SQL table with a column that says number of days, and contains entries like 23, 26, 45, etc... I am trying to convert each entry to a "week number". In essence, what I mean is that if my day entry is between 0 and 6, then, this is Week 1, if it is 7 and 13, then this is Week 2, 14 and 20, week 3, etc... Is there an "efficient" way to do this in SQL?

Thanks. Thomas.

Upvotes: 2

Views: 3550

Answers (2)

You can try this and no need to add +1;

SELECT (Days / 7.00)

Upvotes: 1

John Pasquet
John Pasquet

Reputation: 1842

You need just the standard divide function. It ignores the remainder:

SELECT (Days / 7) + 1

Upvotes: 6

Related Questions