473,402 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

month end date

I have a date such as 1/1/2005, how can i get the month end date for that
month?
Mar 1 '06 #1
6 1979
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Hasanain F. Esmail | last post by:
Hi all, I sincerly thank you all in advance for your help to solve this problem. I have been trying to find a solution to this problem for sometime now but have failed. I am working on a...
7
by: MLH | last post by:
Public Function GetLastDayOfMonth(ByVal dtDay As Date) As Date '************************************************************************** ' Accepts a date. Determines month & year of the date....
6
by: Ante Perkovic | last post by:
Hi, How to declare datetime object and set it to my birthday, first or last day of this month or any other date. I can't find any examples in VS.NET help! BTW, what is the difference...
0
by: larry | last post by:
I am in the process of rewriting one of my first PHP scripts, an event calendar, and wanted to share the code that is the core of the new calendar. My current/previous calendar processed data...
22
by: Stan | last post by:
I am working with Access 2003 on a computer running XP. I am new at using Access. I have a Db with a date field stored as mm/dd/yyyy. I need a Query that will prompt for the month, ie. 6 for...
5
by: tolcis | last post by:
Hi! I have a query that has to return bunch of data based on the calendar month. I have to make sure that it will return data to me for 28 days if it is February and for 31 if it is August(for...
7
by: ajaydesai | last post by:
I have JavaScript code to dispaly two month calendar days at a time, but i have a problem both month that disaplay at a time have same days (for example May and June has same days, June and July have...
6
by: Nkhosinathie | last post by:
hello guys,i've started with classes and i've been given this program below to program and also i will post the source code if you need it.this program reads as folllows. create a class called...
0
by: marlberg | last post by:
Platform: Windows2000, WindowsXP, Windows Vista, etc Language: C#, ASP.NET Pre-compiled Libraries: Enterprise Library 3.0 full I have a requirement to implement in and display in C# and...
3
by: One | last post by:
Hi group - I want to do a SELECT based on a date range - but mySQL syntax expects the month range to be two digits. So I have converted the month to show the leading zero like this : ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.