I want to run some Find statements that only show results from the current two week period of a company - it's the pay period for the company. In other words, not necessarily just the last two weeks of records. A quick search looks like I am not going to be able to use a built-in Time method like Time.now.beginning_of_quarter or Time.now.end_of_quarter. What's the best way to implement this?
If you use the Date class instead of Time, you could make use of the cweek method to get which week of the year a date falls into, and divide that by two to determine which biweekly period.
For instance:
now = Date.today #=> Thu, 10 Dec 2009
period = now.cweek / 2 #=> 25
Note that cweek takes the fact that the year doesn't divide equally into 52 weeks (and therefore not into 26 periods either).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With