Several functions calculated about date days!
This morning, I suddenly used a function of how many days in a certain month, I didn't find the system to bring a function of the system for a long time, so I wrote one, as follows:
** Return how many days in a month Function Howmonthday () Parameters Cdate Local Days AS INTEGER, YEARS AS INTEGAL IF! TYPE ("CDATE") == "D" MessageBox ("The parameter type is incorrect, it should be a date type", "System Tips!") Return Endif Days = IIF (Inlist (Month (CDATE), 1, 3, 5, 7, 8, 10, 12), 31, 30) ** Leap-age calculation method YEARS = year (cdate) IF Month (cdate) == 2 days = IIF (Years% 400 == 0 OR (Years% 4 == 0 and years% 100 <> 0), 29, 28) Endif Return DaysendFunc
Later, Zheng Yu Dago provided me with a function returned to the end of the month. as follows:
Procedure EDOM
* Function: Return to the end of this month
* M.l.y 1998.8.8
Parameters Date_Today
Private all
Set date to ansi
SET CENTURY ON
If Month (DATE_TODAY) <12
Return CTOD (Str (Year (Date_Today), 4, 0) ";
STR (Month (Date_Today) 1, 2, 0) ".01") - 1
Else
Return EDOY (DATE_TODAY)
ENDIF
It is necessary to think that it is necessary to return to the end of the month, I have improved:
cdate = DATE ()
?? CDATE (32-day (cdate)) - day (cdate (32-day (cdate))))
Finally, use this idea to improve how many days of function returning to a month, as follows:
Function Howmonthday () Parameters Cdate Local Days As Integer if! Type ("cdate") == "D" MessageBox ("The parameter type is incorrect, it should be a date type", "System Tips!") Return Endif Days = day (CDATE (32-day (cdate)) - day (cdate (32-day (cdate))) Return DaysendFunc
In fact, there is only one sentence: days = day (cdate (32-day (cdate)) - day (cdate (32-day (cdate)))))))))))))))))))))))))))) also does not need to take a year of forefronts, provincial things.
If you return to the end, then this sentence is changed to: cdate (32-day (cdate)) - day (cdate (32-day (cdate)))
The principle is to calculate the next month in the month, then subtract a few days is the last day of the month.