Possible Duplicate:
How to get the last day of a month?
So far, I have this:
DateTime createDate = new DateTime(year, month, 1).AddMonths(1).AddDays(-1);
Is there a better way?
The Excel EOMONTH function returns the last day of the month, n months in the past or future. You can use EOMONTH to calculate expiration dates, due dates, and other dates that need to land on the last day of a month. Use a positive value for...
To get the first and last day of the current month, use the getFullYear() and getMonth() methods to get the current year and month and pass them to the Date() constructor to get an object representing the two dates. Copied! const now = new Date(); const firstDay = new Date(now. getFullYear(), now.
try yo use DaysInMonth Function which returns the number of days in the required month. This will return (31), so you can get the date format in addition to this number to get last day of this month.
$date = strtotime ( $datestring ); // Last date of current month. $day = date ( "l" , $lastdate );
How about using DaysInMonth
:
DateTime createDate = new DateTime (year, month, DateTime.DaysInMonth(year, month));
(Note to self - must make this easy in Noda Time...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With