473,748 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2004
What I usually do is chose the 1st day of the following month and then
subtract one day.
"CsharpGuy" <Cs*******@disc ussions.microso ft.com> wrote in message
news:38******** *************** ***********@mic rosoft.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*******@disc ussions.microso ft.com> wrote in message
news:38******** *************** ***********@mic rosoft.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.AddMont hs(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*******@disc ussions.microso ft.com> wrote in message
news:38******** *************** ***********@mic rosoft.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.AddMonth s(1)
MonthEnd = New Date(MonthEnd.Y ear, MonthEnd.Month, 1).AddDays(-1)

--
Adrian Parker
Ingenuity At Work Ltd

"CsharpGuy" <Cs*******@disc ussions.microso ft.com> wrote in message news:C8******** *************** ***********@mic rosoft.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*******@disc ussions.microso ft.com> wrote in message
news:38******** *************** ***********@mic rosoft.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.AddMont hs(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*******@disc ussions.microso ft.com> wrote in message
news:38******** *************** ***********@mic rosoft.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(Sys tem.DateTime dateIn, ref System.DateTime dateOut){

dateIn = dateIn.AddMonth s(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.WriteLi ne("Jan: {0}", jan);

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



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

Console.ReadKey ();



return 0;

}

}


"CsharpGuy" <Cs*******@disc ussions.microso ft.com> wrote in message news:C9******** *************** ***********@mic rosoft.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.AddMont hs(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*******@disc ussions.microso ft.com> wrote in message
>> news:38******** *************** ***********@mic rosoft.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
3015
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 project that requires updating data every month. A typical examle is an apartment rental software but could be applied
7
6035
by: MLH | last post by:
Public Function GetLastDayOfMonth(ByVal dtDay As Date) As Date '************************************************************************** ' Accepts a date. Determines month & year of the date. Returns ' the date of the last day of that month (in the same year) '************************************************************************** GetLastDayOfMonth = DateSerial(Year(dtDay), Month(dtDay), 31) End Function If I enter dtDay value of...
6
8989
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 between date and datetime classes? Please, help
0
1904
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 dates only, this code is intended to use more thrifty event descriptions (3rd saturday, last tuesday, etc.) as well as traditional one-of dates. The core here here is quite spartan, no table logic or or db cruft included (I figure you have our own...
22
31209
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 June, and will return all records in that month.
5
2464
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 example). I need to be able to execute it every first of every month for the past 30, 31 or 28 days based on the calendar month. Is there a function or a stored procedure that I can use to do that? Thank you,
7
3827
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 same days etc.) Instate of correct days. Here is my code from 3 files. *************************************************************************************** calendr.js file: isIE = (document.all ? true : false); isDOM =...
6
8081
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 DATE that includs three pieces of information as data member a month(type int),a day(type int) and year(type int).your class should have a constructor with three parameters that uses the parameters to initialise the three data members,for the purpose of...
0
2363
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 ASP.NET a DataGrid with Updatable rows based on a date retrieved from a data table in SQL Server. Below is the design algorithm. 1. Retrieve the Max(rundate) From MyDataTable 2. If the current month -1 = rundate .month from step 1 then 2a. ...
3
3018
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 : $next_month = date('m')+1; $this_month = date('m'); $pre_month = date('m')-1;
0
8995
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9558
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9378
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9331
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8250
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6077
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2216
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.