Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the last day of a month?

Tags:

c#

.net

datetime

How can I find the last day of the month in C#?

For example, if I have the date 03/08/1980, how do I get the last day of month 8 (in this case 31)?

like image 624
Gold Avatar asked Mar 22 '10 14:03

Gold


People also ask

How do I get the last date of a month in Excel?

VBA: Get end of month date. Save and close the window. Then select a cell and type this formula =LastDayInMonth(A2) (A2 contains the date you want to get the end of month date from), then press Enter key and you will get the month's end date.

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 you calculate last week of month?

Calculation of Number of Weeks in a Month For example, the month of August has 31 days (1 week = 7 days). Thus, 31/7= 4 weeks + 3 days. This shows 4 full weeks + 3 days.


2 Answers

The last day of the month you get like this, which returns 31:

DateTime.DaysInMonth(1980, 08); 
like image 57
Oskar Kjellin Avatar answered Nov 06 '22 19:11

Oskar Kjellin


var lastDayOfMonth = DateTime.DaysInMonth(date.Year, date.Month); 
like image 20
Mark Avatar answered Nov 06 '22 19:11

Mark