Progress 4GL/Open edge Code to fetch First and Last date of any month.
In the below example we have fetched the First and Last Date of the current month, you can customized it and can use as per your requirement.
Define variable date1 as date no-undo.
Define variable date2 as date no-undo.
run Default_date.
Message "First Date of Current Month" date1 " ----" " Last Date of Current Month " date2 view-as alert-box.
PROCEDURE Default_date:
Define variable m_session as character no-undo.
Assign
m_session = SESSION:DATE-FORMAT.
IF INDEX (m_session , "m") = 2 THEN
do:
IF INDEX (m_session , "y") = 3 then
do:
IF Month(Today) <> 12 THEN
Assign
date1 = date("01" + "/" + String(Month(Today)) + "/" + String(YEAR(TODAY)))
date2 = date("01" + "/" + String ( ( Month(Today) + 1 ) ) + "/" + String ( YEAR(TODAY)) ) - 1.
else
Assign
date1 = date("01" + "/" + String(Month(Today)) + "/" + String(YEAR(TODAY)))
date2 = date("01" + "/" + "01" + "/" + String ( YEAR(TODAY) + 1 ) ) - 1.
End. /*(m_session , "y") = 3*/
IF INDEX (m_session , "y") = 1 then
do:
IF Month(Today) <> 12 THEN
Assign
date1 = date( String(YEAR(TODAY) ) + "/" + String ( Month(Today) ) + "/" + "01")
date2 = date( String(YEAR(TODAY) ) + "/" + String ( Month(Today) + 1 ) + "/" + "01") - 1 .
Else
Assign
date1 = date( String(YEAR(TODAY) ) + "/" + String ( Month(Today) ) + "/" + "01")
date2 = date( String(YEAR(TODAY) + 1 ) + "/" + "01" + "/" + "01") - 1 .
End. /*INDEX (m_session , "y") = 1*/
End. /*INDEX (m_session , "m") = 2*/
IF INDEX (m_session , "m") = 1 THEN
do:
IF INDEX (m_session , "y") = 3 then
do:
IF Month(Today) <> 12 THEN
Assign
date1 = date( String ( Month(Today) ) + "/" + "01" + "/" + String ( YEAR(TODAY) ) )
date2 = date( String ( Month(Today) + 1 ) + "/" + "01" + "/" + String ( YEAR(TODAY) ) ) - 1.
Else
Assign
date1 = date( String ( Month(Today) ) + "/" + "01" + "/" + String ( YEAR(TODAY) ) )
date2 = date( "01" + "/" + "01" + "/" + String ( YEAR(TODAY) + 1 ) ) - 1.
End. /*(m_session , "y") = 3*/
IF INDEX (m_session , "y") = 2 then
do:
IF Month(Today) <> 12 THEN
Assign
date1 = date( String ( Month(Today) ) + "/" + String ( YEAR(TODAY) ) + "/" + "01" )
date2 = date( String ( Month(Today) + 1 ) + "/" + String ( YEAR(TODAY) ) + "/" + "01" ) - 1.
Else
Assign
date1 = date( String ( Month(Today) ) + "/" + String ( YEAR(TODAY) ) + "/" + "01" )
date2 = date( "01" + "/" + String ( YEAR(TODAY) + 1 ) + "/" + "01" ) - 1.
End. /*INDEX (m_session , "y") = 2*/
End. /*INDEX (m_session , "m") = 1*/
IF INDEX (m_session , "m") = 3 THEN
do:
IF INDEX (m_session , "y") = 1 then
do:
IF Month(Today) <> 12 THEN
Assign
date1 = date( String ( YEAR(TODAY) ) + "/" + "01" + "/" + String ( Month(Today) ) )
date2 = date( String ( YEAR(TODAY) ) + "/" + "01" + "/" + String ( Month(Today) + 1 ) ) - 1 .
Else
Assign
date1 = date( String ( YEAR(TODAY) ) + "/" + "01" + "/" + String ( Month(Today) ) )
date2 = date( String ( YEAR(TODAY) + 1 ) + "/" + "01" + "/" + "01" ) - 1 .
End. /*INDEX (m_session , "y") = 1*/
IF INDEX (m_session , "y") = 2 then
do:
IF Month(Today) <> 12 THEN
Assign
date1 = date( "01" + "/" + String ( YEAR(TODAY) ) + "/" + String ( Month(Today) ) )
date2 = date( "01" + "/" + String ( YEAR(TODAY) ) + "/" + String ( Month(Today) + 1 ) ) - 1 .
Else
Assign
date1 = date( "01" + "/" + String ( YEAR(TODAY) ) + "/" + String ( Month(Today) ) )
date2 = date( "01" + "/" + String ( YEAR(TODAY) + 1 ) + "/" + "01" ) - 1 .
End. /*INDEX (m_session , "y") = 2*/
End. /*INDEX (m_session , "m") = 3*/
END PROCEDURE.
Comments