month end date

B

Brooke

What I usually do is chose the 1st day of the following month and then
subtract one day.
 
R

Ray Booysen

Nice and simple, using your 1/1/2005 as the start date:

System.DateTime _myDate = new DateTime(2005,1,1);
_myDate.AddMonths(1);
_myDate.AddDays(-1);

_myDate will now hold 31st of Jan 2005

Regards
Ray
 
A

Adrian Parker

how about something like..

MonthEnd= MyDate.AddMonths(1)
MonthEnd = New Date(MonthEnd.Year, MonthEnd.Month, 1).AddDays(-1)
 
G

Guest

I just ran this and it gave me 12/31/2004,
unless i showed it wrong
I put the output in a message box
 
B

Brooke

try this...

using System;



public class MyClass {



private static void GetMonthEnd(System.DateTime dateIn, ref System.DateTime dateOut){

dateIn = dateIn.AddMonths(1);

dateIn = dateIn.AddDays(-1);

dateOut = new System.DateTime(dateIn.Year, dateIn.Month, dateIn.Day);

}



public static int Main(string[] args) {

System.DateTime jan = new System.DateTime(2005,3,1);

System.DateTime endOfJan = new System.DateTime();



GetMonthEnd(jan, ref endOfJan);



Console.WriteLine("Jan: {0}", jan);

Console.WriteLine("endOfJan: {0}", endOfJan);



Console.Write("\nPress any key to continue...");

Console.ReadKey();



return 0;

}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top