thread184-1006090
How to validate a date - last day of ANY Month in any Year
Here's a small effective function that will do it.
*
* FUNC Get_Last_Day_Of_Month
*
* Start at day 31 and keep going down/back in days til we find the last good day of this month
LPARAMETERS pdDate && pass in a date you know is valid, with a valid MONTH and YEAR, like "01/01/1999"
TRY
pdDate = CTOD(pdDate) && in case we send in a date as a string - in string format
CATCH
ENDTRY
nMonth = MONTH(pdDate)
nYear = YEAR(pdDate)
* Compute LAST DAY OF MONTH that was passed in
dNewDate = CTOD(' / / ')
nDay = 31
DO WHILE EMPTY(dNewDate) && when Date is invalid, date HighDate will be empty
dNewDate = CTOD(ALLTRIM(TRANSFORM(nMonth)) + '/' + TRANSFORM(nDay) + '/' + ALLTRIM(TRANSFORM(nYear)))
nDay = nDay - 1
ENDDO
RETURN dNewDate
*
* ENDFUNC
*
How to validate a date - last day of ANY Month in any Year
Here's a small effective function that will do it.
*
* FUNC Get_Last_Day_Of_Month
*
* Start at day 31 and keep going down/back in days til we find the last good day of this month
LPARAMETERS pdDate && pass in a date you know is valid, with a valid MONTH and YEAR, like "01/01/1999"
TRY
pdDate = CTOD(pdDate) && in case we send in a date as a string - in string format
CATCH
ENDTRY
nMonth = MONTH(pdDate)
nYear = YEAR(pdDate)
* Compute LAST DAY OF MONTH that was passed in
dNewDate = CTOD(' / / ')
nDay = 31
DO WHILE EMPTY(dNewDate) && when Date is invalid, date HighDate will be empty
dNewDate = CTOD(ALLTRIM(TRANSFORM(nMonth)) + '/' + TRANSFORM(nDay) + '/' + ALLTRIM(TRANSFORM(nYear)))
nDay = nDay - 1
ENDDO
RETURN dNewDate
*
* ENDFUNC
*