Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to find end of month?

Status
Not open for further replies.

santosh1

Programmer
Apr 26, 2002
201
US
I want to get the end of month after six months from today.
For example, if today's date is Oct/23/2003, I want to get
the end date of Apr/30/2004. How can I do this in program?
I was calculating 180 days as six months, but since some months are not exactyly 30 days, I could not get it exactly right.
Thanks in advance.
 
How about this:

Add 31 * 7 to the date which is maximum of days per month times the number of months out plus one since we're going to use the first of that month. Can't really add to the month number since you could cross year boundary.

Concatenate a new date based on this future date using the first day of the month.

dateserial(year(NewDate), month(NewDate), 1)

Subtract 1 day from this concatenated date to get the last day of the previous month.

Hope this helps,
k

 
Create an array of month lengths {31,28,31,30,...,30,31}
Calculate the month (thismonthplus6 = (thismonth+ 6) mod 12)
thismonthplus6 = (10 + 6) mod 12 = 4
the array index = nowplus6 - 1 = 3

hope this helps
BCrowe
 
I found that I have to go 6 months backward instead starting from the beginning day of the given month. So, how do I go 6 months back from today?

For example, today is 10/23/2003, I have to go 6 months back starting from 10/1/2003. So the end date has to be April/1/2003. Thanks again.
 
Maybe something like this would work...


Dim d1 As Date
d1 = #10/23/2002#
Dim d2 As Date


d2 = d1.AddMonths(6) 'OR SUBTRACTMONTHS
Dim x As Integer = d2.DaysInMonth(d2.Year, d2.Month)
MsgBox(d2.AddDays(x - d2.Day))


Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top