Solved

Set Date to be the end of the following month?

Posted on 2007-04-11
4
203 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 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