` Printed Icetips Article

Icetips Article



Par2: Day object methods
1997-11-29 -- Gus Creses
 
For you CW aficionados, here are a few date functions you might find
useful.

!-------------------------------------
OOPDateTime.AlphaMonth  FUNCTION(xMo)
!Returns short name of month "xMo" (range 1-12)
!-------------------------------------
    CODE
    RETURN SUB(FORMAT(DATE(xMo,1,1980),@D3),1,INSTRING(' ',
FORMAT(DATE(xMo,1,1980),@D3),1,1))

!--------------------------------------------------------------------
OOPDateTime.DaysInMonth    FUNCTION(xDate)
! Return number of days in month in which xDate is a date.
!--------------------------------------------------------------------
    CODE
    !Wrap to last day in month.
    RETURN DAY(DATE(MONTH(xDate)+1,1,YEAR(xDate)) - 1)

!--------------------------------------------------------------------
OOPDateTime.IsLeapYear    FUNCTION(xDate)
! Return True the year in which xDate is a date, is a leap year.
!--------------------------------------------------------------------
    CODE
    !Wrap to last day in February.
    RETURN (DAY(DATE(3,1,YEAR(xDate)) - 1) - 28)

!--------------------------------------------------------------------
OOPDateTime.LongMonthName    FUNCTION(xDate)
! Full name of month in xDate
!--------------------------------------------------------------------
  CODE
  RETURN SUB(FORMAT(xDate,@D4),1,INSTRING(' ', FORMAT(xDate,@D4),1,1))


!--------------------------------------------------------------------
OOPDateTime.ShortMonthName    FUNCTION(xDate)
! First three letters of month in xDate
!--------------------------------------------------------------------
  CODE
  RETURN SUB(FORMAT(xDate,@D3),1,INSTRING(' ', FORMAT(xDate,@D3),1,1))


!--------------------------------------------------------------------
OOPDateTime.DayOfWeek     FUNCTION(xDate)
! Return short day of week name in xDate
!--------------------------------------------------------------------
  CODE
  RETURN CHOOSE(((xDate % 7) + 1),'Sunday','Monday','Tuesday','Wednesday',
|
                                  'Thursday','Friday','Saturday')


!--------------------------------------------------------------------
OOPDateTime.ShortDayOfWeek     FUNCTION(xDate)
! Return day of week name in xDate
!--------------------------------------------------------------------
  CODE
  RETURN(CHOOSE(((xDate % 7) +
1),'Sun','Mon','Tue','Wed','Thu','Fri','Sat'))


!--------------------------------------------------------------------------
OOPDateTIme.WorkDays FUNCTION(xLoDate,xHiDate)
!Calculate the number of non-weekend days between two dates
!Count only Monday thru Friday. No regard for statutory holidays.
!--------------------------------------------------------------------------
Ff  LONG,AUTO
Lf   LONG,AUTO
     CODE
     !How many workdays left in first week fragment.
     !----------------------------------------------------
                                             !S M T W T F S
     Ff = CHOOSE(((xLoDate % 7)+1),5,5,4,3,2,1,0)
     !Advance xLoDate to first Sunday after xLoDate.
     !----------------------------------------------
     xLoDate  += Ff
     !How many workdays included in last week fragment.
     !--------------------------------------------------------
                                            !S M T W T F S
     Lf = CHOOSE(((xHiDate % 7)+1),0,1,2,3,4,5,5)
     !Move xHiDate backward to Sunday before xHiDate.
     !-----------------------------------------------
     xHiDate  -= Lf
     !Calculate number of workdays in the set of whole weeks
     !between Sunday (xLoDate) and Sunday (xHiDate) and add
     !the fragments from first and last week. This works even if
     !the first and last day are today and tomorrow. Or both
     !are today.
     !----------------------------------------------------------
     RETURN  ((((xHiDate - xLoDate)/7)*5) + Ff + Lf)



Printed December 3, 2024, 12:00 pm
This article has been viewed/printed 35365 times.