Solved

Set Date to be the end of the following month?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem with SqlConnection 4 160
What .NET website keeps me current? 9 56
Syntax Error 2 45
C#  Radio button search for Date not DateTime 4 35
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…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

910 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

21 Experts available now in Live!

Get 1:1 Help Now