Pergunta
Davidson Espindola · Set. 15, 2021

start and end date of a 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
0
0 72
Discussão (3)1
Entre ou crie uma conta para continuar

Olá, bom dia

Crie este Method Valida data, vc manda a data e o sistema ele verifica se é uma data Válida.

Espero que ajude

ClassMethod ValidaData(strData As %String) As %Boolean
{
 New (strData)
 ;
 If strData'?2N1"/"2N1"/"4Quit 0
 Set (Mult,Div,Resto,Dia,Mes,Ano)=""
 Set Dia=$P(strData,"/",1)
 Set Mes=$P(strData,"/",2)
 Set Ano=$P(strData,"/",3)
 If (Dia<"01") Quit 0
 If (Mes>"12")!(Mes<"01") Quit 0
 If (Ano<1900)!(Ano>2050) Quit 0
 If (Mes="01")!(Mes="03")!(Mes="05")!(Mes="07")&(Dia>31) Quit 0
 If (Mes="08")!(Mes="10")!(Mes="12")&(Dia>31) Quit 0
 If (Mes="04")!(Mes="06")!(Mes="09")!(Mes="11")&(Dia>30) Quit 0
 If (Mes="02")&(Dia>29) Quit 0
 If (Mes="02") {
 Set Resto=Ano#4
 ;Set Div=Ano\4
 ;Set Mult=Div*4
 ;Set Resto=Ano-Mult
 If (Resto=0)&(Dia>29) Quit 0
 If (Resto>0)&(Dia>28) Quit 0
 }
 Quit 1
}
 

max day of the month :

max= 28+$e(3_(Ano#4=0)_3232332323,Mes)

set year = 2015 
set month = 2 
set start = $zdateh(year_"-"_month_"-1",3) 
set end = $zdateh((year+$select(month=12:1,1:0))_"-"_(month+$select(month=12:-11,1:1))_"-1",3)-1 
write $zdate(start,3)_" / "_ $zdate(end,3)

// 2015-02-01 / 2015-02-28