day of the month
Hello everyone
I use cache script, I would like to know from you if there is any function or class in the cache where I can get the start and end date of a given month:
Example: What is the first and last day of the month of February 2015.
Grateful.
Davidson
Product version: Caché 2018.1
$ZV: Cache for Windows (x86-64) 2018.1.5 (Build 659) Mon Mar 22 2021 07:15:21 EDT
See %SYSTEM.SQL (LASTDAY, DAYOFMONTH, etc.)
Hi @Davidson Espindola
First date of every month will be 1 which you can concat with current month and year however for last month you can use LAST_DAY cache function by passing any date of desire month.
SELECT LAST_DAY('2004-02-25')
For details check below documentations:
https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY...
https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY...
Thanks
PERFECT THANK YOU
grateful.
If you don't want to mess with SQL functions, this is still easy, especially taking advantage of date format 8 (ANSI):
DOM ; SRS 2021-09-15 PUBLIC DOMAIN NO WARRENTY
; Return $HOROLOG date for first day of the month.
FIRST(y,m) QUIT $ZDATEH(y*100+m*100+1,8)
; Return $HOROLOG date for last day of the month.
LAST(y,m) SET m=m+1 SET:m>12 m=m-12,y=y+1
QUIT $ZDATEH(y*100+m*100+1,8)-1
Test for this year with:
USER>FOR i=1:1:12 WRITE !,i," ",$$FIRST^DOM(2021,i)," ",$$LAST^DOM(2021,i)
1 65745 65775
2 65776 65803
3 65804 65834
4 65835 65864
5 65865 65895
6 65896 65925
7 65926 65956
8 65957 65987
9 65988 66017
10 66018 66048
11 66049 66078
12 66079 66109
PERFECT THANK YOU
grateful.
<Nitpicking ON>
For the LAST() function you can also use just an expression:
<Nitpicking OFF>
By the way, if you are just interested, how many days a month in a given year has, there is a simple formula:
In the above formula, it's OK to use short leap year calculation (y#4=0) for contemporary dates (date from 1901 until 2099) else case you have to stick to the long format: (y#4=0)-(y#100=0)+(y#400=0)
I like to be in chage of my own code. If I want the $h of the last day of the month
I code the first day of the following month resolve into hDate=($zdh("01 MMM yyyy",2)-1
Now you can use it with $zd(hDate,2,,4)
PERFECT THANK YOU
grateful.
Social networks
InterSystems resources
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue