Solved

Set Date to be the end of the following month?

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now