0

I have an array of dates and I need to find if the user had an active membership during those dates.

['2016-04-17', '2016-04-18', '2016-04-22', '2016-04-23']

Sometimes a membership can't be charged and go inactive for a few days until the next payment is processed, or the user may cancel and reactivate later.

The way I'm solving this is having a transactions table with a paid_at column and expires_at (expiring date set after 1 month of paid).

I would need to perform a where clause to return me the dates that match between those two columns in all the records in the database. I don't need the record itself, just returning the date means should be enough to know it was a day while the membership was active.

Im having a hard time understanding how such a query could be made. Any suggestion?

Martin
  • 11,216
  • 23
  • 83
  • 140
  • Can you please show table structure, or at least some sample data from the two tables? – Tim Biegeleisen Apr 25 '17 at 02:42
  • The table is done using ruby on rails, so im not sure is relevant. But the description in the question should be enough for the problem itself. Im interested in how to perform such query between two date time fields. I can adjust it later to the edge cases. – Martin Apr 25 '17 at 02:45
  • http://stackoverflow.com/questions/10170544/getting-results-between-two-dates-in-postgresql – Tim Biegeleisen Apr 25 '17 at 02:45
  • The question seems to be asking about date ranges, but this is an array of distinct particular dates not necessarily continuos. There are no start or end date given here. Please see the input array above. – Martin Apr 25 '17 at 02:50
  • Im having a hard time understanding what a query you try to made. Please update your question with clear sample of "those two columns in all the records in the database", so we could understand what should be in `where` clause – Vao Tsun Apr 25 '17 at 07:35

0 Answers0