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;
}
}
"CsharpGuy" <Cs*******@discussions.microsoft.com> wrote in message news:C9**********************************@microsof t.com...
I just ran this and it gave me 12/31/2004,
unless i showed it wrong
I put the output in a message box
"Ray Booysen" wrote:
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
CsharpGuy wrote: > do you have a code snippet I could look at that is doing this?
>
> "Brooke" wrote:
>
>> What I usually do is chose the 1st day of the following month and then
>> subtract one day.
>>
>>
>> "CsharpGuy" <Cs*******@discussions.microsoft.com> wrote in message
>> news:38**********************************@microsof t.com...
>>> I have a date such as 1/1/2005, how can i get the month end date for that
>>> month?
>>>
>>>
>>
>>
--
Ray Booysen
rj********@rjb.za.net