Recent posts:
Recent replies:

If you don't want to mess with SQL functions, this is still easy, especially taking advantage of date format 8 (ANSI):

    ; 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

Instead of using the first piece with $PIECE(variable,"("), I recommend using $NAME(@variable,0). $NAME has the advantage that it will likely be updated in the event of any changes to introduce new variable syntax, while $PIECE(variable,"(") will remain stuck with the simple syntax. One advantage of $NAME(@varaible,0) is that $NAME will also check the syntax of all the subscripts. One disadvantage is that all subscripts must be defined.

Yes, but it is unsupported. The expression $ZUTIL(70,2,value) will return value encoded for use as a subscript subject to the current default subscript encoding. You can combine this with $LENGTH(), so $LENGTH($ZUTIL(70,2,value)) to get the length of a subscript once encoded. This technique should never find its way into production code. However, if you just want to understand how various codepoints are encoded, you can use it for experimentation.

Stuart has no followers yet.
Stuart has not followed anybody yet.
Global Masters badges:
Stuart has no Global Masters badges yet.