Get all entries within working hours excluding weekends

I want to make two queries into Useractivities, one where i find all entries within working hours (mon-fri 08-16) and one where I find all entries outside of this timespan.

Useractivity.where('activity = ? AND created_at >= ? AND EXTRACT (HOUR from created_at) BETWEEN ? AND ?', 'login',Time.now.since(-7.days).to_date, 8,16).count

Useractivity.where('activity = ? AND created_at >= ? AND EXTRACT (HOUR from created_at) NOT BETWEEN ? AND ?', 'login',Time.now.since(-7.days).to_date, 8,16).count

How can i exclude saturdays and sundays for the first query, and include them (for all hours) in the second query?

Answers


You add an extra condition in the WHERE clause.

For the working days it is:

... AND EXTRACT(dow FROM created_at) BETWEEN 1 AND 5 ...

And for weekend days:

... AND EXTRACT(dow FROM created_at) NOT BETWEEN 1 AND 5 ...

Need Your Help

Localizations for abc_* strings (from com.android.support:appcompat-v7) appeared in my APK

android localization android-gradle

In recent builds of an android application I wrote I see the appearance of a lot of file containing translations for several strings that I never added.

Mapping list of objects

c# dao dto object-object-mapping

I'm manually creating a mapper that converts a DAO object to a DTO. *** BTW, I'm aware of AutoMappers but I want to do this by hand for a few reasons.