I've been trying to count the age of something in weekdays. I've tried the method detailed in this question, http://stackoverflow.com/questions/883615/given-a-date-range-how-to-calculate-the-number-of-weekends-partially-or-wholly-wi but it doesn't seem to fit my usecase.
An item has a created DATETIME
in the database, and I need to mark it as old if the created date is over 2 days old. However, the client has requested that age only count week days (Mon to Fri) and exclude Sat+Sun.
So far, my pseudo code looks like the following,
now - created_datetime = number_of_days
for(i number_of_days)
if(created_datetime - i)
is a weekday, then age++
There must be a cleaner way of achieving this? As if an item were to get very old, looping through each day of it's age, looking for a weekend day would impact speed quite a bit.
Any ideas would be great! Thanks