3

I have the following:

firstDate = InputBox("Insert the first report's date desired to obtain", "Report Information - Start", "YYYY-MM-DD")

So the user inserts the date, lets say: 2015-04-17

I am trying to find a way by which I can increase the date's value for a specific position (day->DD), for example:

dateIncrease = Mid(firstDate, 9, 2)+1

I am expecting the above to return 18 (17+1)

How can I increase the value of the date? Please help. Let me know if I wasn't clear enough. Thanks.

F0l0w
  • 243
  • 5
  • 15
  • I deleted my answer since it was not helpful with what you were asking (I sort of misunderstood your question). I believe joehanna has the answer to what you were looking for. – John Odom Apr 20 '15 at 18:29

2 Answers2

2

This is what you're looking for:

firstDate  = "2015-04-17"
dateIncrease = DatePart("d", DateAdd("d", 1, DateValue(firstDate )))
Uri Goren
  • 13,386
  • 6
  • 58
  • 110
2

Following on from @Uri, you can also use these statements to increment any part of the date

Dim firstDate As String
Dim dateIncrease As Integer

firstDate = "2015-04-17"

'Increment the day part
dateIncrease = DatePart("d", DateAdd("d", 1, DateValue(firstDate)))

'Increment the month part
dateIncrease = DatePart("m", DateAdd("m", 1, DateValue(firstDate)))

'Increment the year part
dateIncrease = DatePart("yyyy", DateAdd("yyyy", 1, DateValue(firstDate)))
Community
  • 1
  • 1
joehanna
  • 1,471
  • 1
  • 11
  • 22
  • Can you please explain in what does the DatePart consists? Thanks – F0l0w Apr 20 '15 at 18:37
  • The `DatePart` functions gets a date, and a representation of it's components ("d" for day,"m" for month, "y" for year) and returns one component of it – Uri Goren Apr 20 '15 at 19:42