Solved

Set Date to be the end of the following month?

Posted on 2007-04-11
4
204 Views
Last Modified: 2010-04-15
Hi there wonder if you can help me?

If I have a variable called:

DateTime getLastMonthDate = new DateTime();

How do I set getLastMonthDate to be the end of the following month?

Thanks
0
Comment
Question by:mousemat24
  • 2
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
Thalox earned 500 total points
ID: 18888530
try this:

DateTime now = DateTime.Now;
// add month
now = now.AddMonth(2);
// make date 1. that month
DateTime getLastMonthDate = new DateTime(now.Year, now.Month, 1);
// one day back
getLastMonthDate = getLastMonthDate.AddDays(1);

This should work;

Thalox
0
 
LVL 9

Expert Comment

by:Thalox
ID: 18888545
oops,

should be
getLastMonthDate = getLastMonthDate.AddDays(-1);
0
 

Author Comment

by:mousemat24
ID: 18893462
Thalox

Thanks for that!! thats what I wanted
0
 

Author Comment

by:mousemat24
ID: 18893606
where did Thalox come from :-S ? LOL
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question