VBScript - increasing the value of a variable

I have the following:

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

      

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

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

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

      

I expect the above to return 18 (17 + 1)

How do I increase the date value? Please help. Let me know if I am not clear enough. Thank.

+3


source to share


2 answers


This is what you are looking for:



firstDate  = "2015-04-17"
dateIncrease = DatePart("d", DateAdd("d", 1, DateValue(firstDate )))

      

+2


source


Following @Uri you can also use these instructions 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)))

      

+2


source







All Articles