I would like to perform a SQL to get a list of dates on the last day of each month.
Example: From a list of 01/01/2016 until 12/31/2016 return the last days of each month: 1/31/2016, 2/28/2016 ... 12/31/2016.
The database is in FileMaker.
I would like to perform a SQL to get a list of dates on the last day of each month.
Example: From a list of 01/01/2016 until 12/31/2016 return the last days of each month: 1/31/2016, 2/28/2016 ... 12/31/2016.
The database is in FileMaker.
In the filemaker I did not get any generic solution via SQL, the way was to generate multiple queries for the period using the OFFSET and FETCH FIRST clauses
In PostgreSQL
you can use this way:
SELECT TO_CHAR(data, 'YYYY-MM-01')::DATE +
(INTERVAL'1 MONTH' - INTERVAL'1 DAY') AS data
FROM tabela
GROUP BY data
At a glance in this documentation .
SQL Server 2012 forward you can use the following:
SELECT EOMONTH(Data) from Datas
In other versions of SQL Server you can do something like this:
select DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,Data)+1,0)) from Datas
In Oracle:
select LAST_DAY(Data) from Datas
Another way to perform this query, only with calculations:
SELECT
DATEADD(month, ((YEAR(data) - 1900) * 12) + MONTH(data), -1)
FROM
Datas
See it working: SQLFiddle
In FileMaker, the date (month; day; year) function , when 0 is entered in the day
parameter, returns the last day of the previous month. For example, date(2;0;2016)
returns the last day of January 2016.
Combined use of date () , year () and month () allows you to get the last day of the table date month. Assuming the column name is DateTable, we can have something similar to date((month(DataVenda) +1); 0; year(DataVenda))