Add one day to a date and save it as a new variable in Smalltalk

208 Views Asked by At

so here is the problem. I want to take a date from lastDate and put it to nextDate, but also add one day to the variable nextDate. Anyone know how to do that?

| lastDate nextDate |
lastDate := Date 
            newDay: 10
            monthNumber: 5
            year: 2019.
nextDate := lastDate.

HELP HERE

^nextDate
1

There are 1 best solutions below

8
tukan On BEST ANSWER

It would help to know which Smalltalk you are using.

I will use Smalltalk/X-jv branch for the examples as it is easies for me:

| lastDate nextDate |

lastDate := Date newDay: 10
                  month: 5
                   year: 2019.

nextDate := lastDate addDays: 1.
^ nextDate

To add one day you can use the #addDays: message to your lastDate.

Edit: due to comment

To add a year you can send message #addYears: