Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you find the last day of the month? [duplicate]

Tags:

c#

datetime

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?

like image 609
Irwin Avatar asked Nov 02 '10 15:11

Irwin


People also ask

How do you figure out the last day of the month?

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...

How do you find the first and last day of the current month?

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.

How do I get the last day of the month in VB net?

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.

How do you get the last day of the month in PHP?

$date = strtotime ( $datestring ); // Last date of current month. $day = date ( "l" , $lastdate );


1 Answers

How about using DaysInMonth:

DateTime createDate = new DateTime (year, month,                                     DateTime.DaysInMonth(year, month)); 

(Note to self - must make this easy in Noda Time...)

like image 183
Jon Skeet Avatar answered Oct 04 '22 00:10

Jon Skeet