By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,087 Members | 1,508 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,087 IT Pros & Developers. It's quick & easy.

month end date

P: n/a
I have a date such as 1/1/2005, how can i get the month end date for that
month?
Mar 1 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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?

Mar 1 '06 #2

P: n/a
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?


Mar 1 '06 #3

P: n/a
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
Mar 1 '06 #4

P: n/a
how about something like..

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

--
Adrian Parker
Ingenuity At Work Ltd

"CsharpGuy" <Cs*******@discussions.microsoft.com> wrote in message news:C8**********************************@microsof t.com...
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?
>
>


Mar 1 '06 #5

P: n/a
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

Mar 1 '06 #6

P: n/a
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

Mar 1 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.