ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   can you add months to a date? (https://www.excelbanter.com/excel-programming/427691-can-you-add-months-date.html)

greg

can you add months to a date?
 
can you add months to a date?
So for example you have a date. any date. like 5/20/2010
Then I want to add 6 months to the date. Then get 11/20/2010
Is there a way to do this in vba/excel?

thanks



smartin

can you add months to a date?
 
greg wrote:
can you add months to a date?
So for example you have a date. any date. like 5/20/2010
Then I want to add 6 months to the date. Then get 11/20/2010
Is there a way to do this in vba/excel?

thanks


It depends on what you mean by "month".

For example, you have a date like "8/31/yyyy". Add 6 months. February...31?

FSt1

can you add months to a date?
 
hi
something like this might work for you'
assuming you have a date value in a cell......
Sub dateadd()
Dim d As Date
d = Range("I3").Value
d = DateSerial(Year(d), Month(d) + 6, Day(d))
MsgBox d
End Sub

regards
FSt1

"greg" wrote:

can you add months to a date?
So for example you have a date. any date. like 5/20/2010
Then I want to add 6 months to the date. Then get 11/20/2010
Is there a way to do this in vba/excel?

thanks




greg

can you add months to a date?
 
cool thanks

"FSt1" wrote in message
...
hi
something like this might work for you'
assuming you have a date value in a cell......
Sub dateadd()
Dim d As Date
d = Range("I3").Value
d = DateSerial(Year(d), Month(d) + 6, Day(d))
MsgBox d
End Sub

regards
FSt1

"greg" wrote:

can you add months to a date?
So for example you have a date. any date. like 5/20/2010
Then I want to add 6 months to the date. Then get 11/20/2010
Is there a way to do this in vba/excel?

thanks






Rick Rothstein

can you add months to a date?
 
Just so you understand what smartin was trying to tell you, try the code
FSt1 gave you with a date of January 31st and add one month to it... is that
the date you expected?

--
Rick (MVP - Excel)


"greg" wrote in message
...
cool thanks

"FSt1" wrote in message
...
hi
something like this might work for you'
assuming you have a date value in a cell......
Sub dateadd()
Dim d As Date
d = Range("I3").Value
d = DateSerial(Year(d), Month(d) + 6, Day(d))
MsgBox d
End Sub

regards
FSt1

"greg" wrote:

can you add months to a date?
So for example you have a date. any date. like 5/20/2010
Then I want to add 6 months to the date. Then get 11/20/2010
Is there a way to do this in vba/excel?

thanks







Dana DeLouis

can you add months to a date?
 
can you add months to a date?

Hi. Just be aware of some differences. The first two round down, and
the last one does not.

Sub Demo()
Dim d As Date
Dim t As Date

d = DateValue("1/31/2009")

t = WorksheetFunction.EDate(d, 1)
Debug.Print t

t = DateAdd("m", 1, d)
Debug.Print t

t = DateSerial(Year(d), Month(d) + 1, Day(d))
Debug.Print t
End Sub

Returns:
2/28/2009
2/28/2009
3/3/2009

Note: I'm using Excel 2007, so EDate is a worksheet function.

Dana DeLouis
= = = = =


greg wrote:
cool thanks

"FSt1" wrote in message
...
hi
something like this might work for you'
assuming you have a date value in a cell......
Sub dateadd()
Dim d As Date
d = Range("I3").Value
d = DateSerial(Year(d), Month(d) + 6, Day(d))
MsgBox d
End Sub

regards
FSt1

"greg" wrote:

can you add months to a date?
So for example you have a date. any date. like 5/20/2010
Then I want to add 6 months to the date. Then get 11/20/2010
Is there a way to do this in vba/excel?

thanks







All times are GMT +1. The time now is 06:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com