I passed in a DateTime object, and want to get its end date of the month. Is
there a easy way to do it?
Thanks. 7 1996
How about something like
(new DateTime(n,1,04)).AddMonth(1).AddDay(-1);
Have not compiled this, but you get the idea.
"Bob" <bo******@yahoo.com> wrote in message
news:#A**************@TK2MSFTNGP12.phx.gbl... I passed in a DateTime object, and want to get its end date of the month.
Is there a easy way to do it?
Thanks.
I posted this a few weeks ago the last time it was asked :-)
Public Function EndOfMonth(ByVal d As Date, ByVal m As Integer) As Date
Return d.AddMonths(m + 1).AddDays(-d.Day)
End Function
If you send it a date and 0 for the m (months) parameter it returns the end
of the month for the date. Plus you can send it a 1, 2, 12 or whatever for
months in the future. I assume it will work with months in the past but I
can't recall if I tested that.
Tom
"Bob" <bo******@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... I passed in a DateTime object, and want to get its end date of the month.
Is there a easy way to do it?
Thanks.
Hi Bob,
I saved this very well, it is from NAK who was active here some time ago and
we had fun when he was making it, because somebody was asking how to get the
last day of the week, but than it became the month. It is maybe not your
question, but I have saved it so long that I send it and maybe you can use
it.
:-))
The following function will tell you if it is currently the last
"monday,tuesday,wednesday.." of the month. For example. if you pass it
Saturday today (30 August 2003) it will return True.
\\\
'Made by Nick Paterman
Public Function isLastDayOfMonth(ByVal iDay As DayOfWeek) As Boolean
If (Date.Now.DayOfWeek = iDay) Then
If (Date.Now.Day < Date.DaysInMonth(Now.Year, Now.Month)) Then
Dim pIntDaysLeft As Integer = Date.DaysInMonth(Now.Year,
Now.Month) - Date.Now.Day
Return (pIntDaysLeft < 7)
Else
'IS THE LAST DAY OF THE MONTH!
Return (True)
End If
Else
'THAT ISNT TODAYS DAY
Return (False)
End If
End Function
///
I hope this helps a little bit?
Cor
Thanks, Guys!!
"Bob" <bo******@yahoo.com> wrote in message
news:#A**************@TK2MSFTNGP12.phx.gbl... I passed in a DateTime object, and want to get its end date of the month.
Is there a easy way to do it?
Thanks.
Cor,
Interesting way to handle it... so if I want to know which day of the week
is the end of the month I call it in a loop from 1 to 7 and break when I get
a True?
I probably would have it return the LastDayOfMonth and let the client a) use
the value directly or b) run through their own local loop or case statement
without the need to keep asking the function if it guessed correctly yet.
But that's just me :-)
Tom
"Cor" <no*@non.com> wrote in message
news:Oa**************@TK2MSFTNGP09.phx.gbl... Hi Bob,
I saved this very well, it is from NAK who was active here some time ago
and we had fun when he was making it, because somebody was asking how to get
the last day of the week, but than it became the month. It is maybe not your question, but I have saved it so long that I send it and maybe you can use it.
:-))
The following function will tell you if it is currently the last "monday,tuesday,wednesday.." of the month. For example. if you pass it Saturday today (30 August 2003) it will return True. \\\ 'Made by Nick Paterman Public Function isLastDayOfMonth(ByVal iDay As DayOfWeek) As Boolean If (Date.Now.DayOfWeek = iDay) Then If (Date.Now.Day < Date.DaysInMonth(Now.Year, Now.Month)) Then Dim pIntDaysLeft As Integer = Date.DaysInMonth(Now.Year, Now.Month) - Date.Now.Day Return (pIntDaysLeft < 7) Else 'IS THE LAST DAY OF THE MONTH! Return (True) End If Else 'THAT ISNT TODAYS DAY Return (False) End If End Function ///
I hope this helps a little bit?
Cor
Hi Tom,
I was so happy I could send it, I saved it well just for an occassion that
it should happen. It was something Nick has been very busy with, maybe he
sees this and we see him again.
I was thinking if I would make something myself. Because the end date of the
month is the date of the first day of the next month minus 1. But I saw so
many answers already that I only did send this.
Cor Interesting way to handle it... so if I want to know which day of the week is the end of the month I call it in a loop from 1 to 7 and break when I
get a True?
Bob <bo******@yahoo.com> wrote: I passed in a DateTime object, and want to get its end date of the month. Is there a easy way to do it?
Aside from the other ways people have suggested:
int lastDay = DateTime.DaysInMonth (myDate.Year, myDate.Month);
DateTime endOfMonth = myDate.AddDays(lastDay-myDate.Day);
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: androtech |
last post by:
Hello,
I'm looking for a function that returns a date range for a specified week
number of the year.
I'm not able to find functions like this anywhere. Any pointers/help would
be much...
|
by: Richard Hollenbeck |
last post by:
I'm trying to write some code that will convert any of the most popular
standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan
1908) and compare the first with the second and...
|
by: Adrian |
last post by:
I hit on this problem converting a VB.NET insurance application to C#.
Age next birthday calculated from date of birth is often needed in
insurance premium calculations.
Originally done using...
|
by: Assimalyst |
last post by:
Hi,
I have a working script that converts a dd/mm/yyyy text box date entry
to yyyy/mm/dd and compares it to the current date, giving an error
through an asp.net custom validator, it is as...
|
by: Niyazi |
last post by:
Hi everyone,
I have a sql table that has 5 column as:
cl1Month - cl1_3Month - cl3_6Month - cl6_12Month - clMoreThan12Month
Now I have to date and I have to find the differences and check as...
|
by: Bob Sanderson |
last post by:
I have a PHP web page which uses a HTML form. I would like to enter dates
into the date fields using a JavaScript calendar, similar to the way
phpMyAdmin does. Can anyone recommend a JavaScript...
|
by: Jes |
last post by:
Dear all
I have a date field on a HTML form where the user is asked to key in
dd/mm/yyyy
However, when that is written to MySql it is either not accepted or
another value is tored in the...
|
by: ashore |
last post by:
Guys, the line below just returned "Dec 07" as the date for one month
back from today. Hardly life-threatening, but any thoughts?
<?php print date("M `y", mktime(0, 0, 0, date("m")-1, date("d"),...
|
by: mshroom12 |
last post by:
I am having trouble with the following project on hand. I use Eclipse to do my work in Java. This is what I'm supposed to complete.
Date Validation
In this exercise you will write a program...
|
by: janetopps |
last post by:
I have a news website, with asp pages, which was on Access, and i upgraded to MySQL, i used Bullzip to transfer the data. It had about 1000 pages, which im now able to pull up on the public side. Im...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
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...
| |