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?
ToString("MMM"); // to get the full month name string month_name = date. ToString("MMMM");
=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.
Day); DateTime endDate = startDate. AddMonths(1). AddDays(-1);
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() .
Why not use DateTime.AddMonths
For example:
var lastMonth = DateTime.Now.AddMonths(-1).ToString("Y");`
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