Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a method to get last month name and year in C#

DateTime.Now.ToString("Y") returns me : August 2013

Is there an easy method to get last month in the same format?

Something like : DateTime.LastMonth.ToString("Y") and output will be : July 2013

I know this method doesnt exists :) but maybe there is something else to achieve that output? Or I will need to create my own method for that?

like image 412
akd Avatar asked Aug 01 '13 15:08

akd


People also ask

How to get date with month name in c#?

ToString("MMM"); // to get the full month name string month_name = date. ToString("MMMM");

How do I find the last date of the month?

=EOMONTH(A2, -1) - returns the last day of the month, one month before the date in cell A2. Instead of a cell reference, you can hardcode a date in your EOMONTH formula.

How can I get the last date of a previous month in C#?

Day); DateTime endDate = startDate. AddMonths(1). AddDays(-1);

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

To determine the date for the first day in a month, use date shifting (an application of date arithmetic). To determine the date for the last day, use the LAST_DAY() function. To determine the number of days in a month, find the date for the last day and use it as the argument to DAYOFMONTH() .


1 Answers

Why not use DateTime.AddMonths

For example:

var lastMonth = DateTime.Now.AddMonths(-1).ToString("Y");`
like image 141
Darren Avatar answered Oct 04 '22 21:10

Darren