473,386 Members | 1,673 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,386 software developers and data experts.

EndOFMonth Functions

I've been an Access Programmer for several years, and found that the EndOfMonth function is very valuable when trying to do closing dates and the like..

Is there a function in VB.Net that does the same thing? I've been checking the help files and found numerous date functions, but not one end of month or last day of month or month end function. IS there such a function? Can some one please send me a link to where I can find this information, or better yet, an example of how it works? Thanks very much... Coleen

---
Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest Community Website: http://www.dotnetjunkies.com/newsgroups/
Nov 20 '05 #1
5 7491
<coleenholley> wrote...
Is there a function in VB.Net that does the same thing?


Basically you use the methods you have to calculate the ones you want...so
this might work:

Public Function EndOfMonth(ByVal d As Date, ByVal m As Integer) As Date
Return d.AddMonths(m + 1).AddDays(-d.Day)
End Function

You can test it like this:

Console.WriteLine(Now.ToString)
Console.WriteLine(EndOfMonth(Now, 0).ToString)
Console.WriteLine(EndOfMonth(Now, 1).ToString)
Console.WriteLine(EndOfMonth(Now, 12).ToString)

It depends a little on whether you think adding zero should be the end of
this month. I did, so that's why I add one to the month value passed to the
formula.

Tom

Nov 20 '05 #2
Thank you very much! I will try this. I'm looking at DatePart, DateSerial, DateAdd functions. The problem is that none of them allow you to take today() and get the end of month value using a simple function. Then you have to take into account leap year for February when writing a function to find the last day of each month with 31 days and each month with 30 days. It's was much simpler in Access - why oh why - didn't Microsoft incorporate this functionality into VB.Net? It was SO useful! Thanks Again. Coleen

---
Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest Community Website: http://www.dotnetjunkies.com/newsgroups/
Nov 20 '05 #3
<coleenholley> schrieb
I've been an Access Programmer for several years, and found that the
EndOfMonth function is very valuable when trying to do closing dates
and the like...

Is there a function in VB.Net that does the same thing? I've been
checking the help files and found numerous date functions, but not
one end of month or last day of month or month end function. IS
there such a function? Can some one please send me a link to where I
can find this information, or better yet, an example of how it works?
Thanks very much... Coleen


I didn't find the EndOfMonth function in the Access documentation. You are
probably looking for System.DateTime.DaysInMonth:

msgbox date.daysinmonth(2004, 1)
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4
There are a number of different calendars (depending what region of the
world you are talking about, and what era). Each calendar implements a
GetDaysInMonth method.
To use the current region's calendar, use:

Imports System.Globalization
..
..
..
CultureInfo.CurrentCulture.Calendar.GetDaysInMonth (year, month)

To get the current month's last day, use:

Function EndOfMonth() As Integer
Dim d As Date = Date.Today();
Return CultureInfo.CurrentCulture.Calendar.GetDaysInMonth (d.Year,
d.Month)
End Function

The DateTime type (Date type in VB) has a similar method called DaysInMonth,
but it doesn't respect different regional calendars. It hardcodes a 365 day
year, but checks for leapyear. If you are writing an app capable of being
used internationally, it's best to use the regional calendar instead.

-Rob Teixeira [MVP]

<coleenholley> wrote in message
news:uy**************@TK2MSFTNGP09.phx.gbl...
Thank you very much! I will try this. I'm looking at DatePart, DateSerial, DateAdd functions. The problem is that none of them allow you
to take today() and get the end of month value using a simple function.
Then you have to take into account leap year for February when writing a
function to find the last day of each month with 31 days and each month with
30 days. It's was much simpler in Access - why oh why - didn't Microsoft
incorporate this functionality into VB.Net? It was SO useful! Thanks
Again. Coleen
---
Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest

Community Website: http://www.dotnetjunkies.com/newsgroups/
Nov 20 '05 #5
Thanks Rob & Tom :-)

Between the two of you, I have my answer. I appreciate your help. I do need to know leap years; what I am doing is calculating a post-mark date based on a selected report period. If the report period is current, I need to calculate the last day of the month for the reporting period, and add 1 month to it, so the DateAdd function works great, but finding the correct last day of month was a challenge. Thanks very much for your assistance. Coleen

---
Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest Community Website: http://www.dotnetjunkies.com/newsgroups/
Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: hokiegal99 | last post by:
A few questions about the following code. How would I "wrap" this in a function, and do I need to? Also, how can I make the code smart enough to realize that when a file has 2 or more bad...
99
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less...
1
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is visible in those assemblies from a...
47
by: Richard Hayden | last post by:
Hi, I have the following code: /******************************** file1.c #include <iostream> extern void dummy(); inline int testfunc() {
25
by: Stijn Oude Brunink | last post by:
Hello, I have the following trade off to make: A base class with 2 virtual functions would be realy helpfull for the problem I'm working on. Still though the functions that my program will use...
2
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to...
7
by: Tim ffitch | last post by:
Hi I have created a VB dll file that contains common functions I use across various projects in VB, Access and Excel. Rather than have to code the functions in each I decided to use the dll...
23
by: Timothy Madden | last post by:
Hello all. I program C++ since a lot of time now and I still don't know this simple thing: what's the problem with local functions so they are not part of C++ ? There surely are many people...
7
by: Immortal Nephi | last post by:
My project grows large when I put too many member functions into one class. The header file and source code file will have approximately 50,000 lines when one class contains thousand member...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.