function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
rsg00usarsg00usa 

Add n days to a date

Being new to Apex can someone guide me in how I would add days to a date similar to how it is done in Java:


GregorianCalendar worldTour = new GregorianCalendar(1872, Calendar.OCTOBER, 2);
worldTour.add(GregorianCalendar.DATE, 80);
Date d = worldTour.getTime();
DateFormat df = DateFormat.getDateInstance();
String s = df.format(d);
System.out.println("80 day trip will end " + s);


Thanks,

Scott

SuperfellSuperfell

use addDays & friends.

 

Date d = getSomeDate();

Date nextWeek = d.addDays(7); 

IanfitzingIanfitzing
addDays(-1) didn't work for me but Date d = getSomeDate() - 1; did. Just thought I would update the answer for the next person who finds this.