Written by

Question Permo Jacobs · Jan 16, 2018

How do i get the last date of the every month

Hi I'm new in cache ... How do i get the last date of the every month

Comments

Sylvie Greverend · Jan 16, 2018

>w $System.SQL.DATEADD("d",-1,"2017-01-01")
2016-12-31 00:00:00
 

0
Dmitry Maslennikov · Jan 16, 2018

date in Cache stored in $horolog, which is just number of days from 01/01/1841. So to get the last day of the month you need the date for the first day of next month minus 1.

USER>set y=2018 for m=1:1:12 set d=$zdh(m_"/01/"_y) w !,$zd(d-1, 4)

31/12/2017
31/01/2018
28/02/2018
31/03/2018
30/04/2018
31/05/2018
30/06/2018
31/07/2018
31/08/2018
30/09/2018
31/10/2018
30/11/2018
0
Eduard Lebedyuk · Jan 16, 2018

For SQL, use LAST_DAY function - it's a date function that returns the date of the last day of the month for a date expression:

SELECTLAST_DAY('2004-02-25')

It's also available in Caché ObjectScript:

Write $SYSTEM.SQL.LASTDAY("2004-02-25")
0