Solved

Set Date to be the end of the following month?

Posted on 2007-04-11
4
206 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

624 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