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

Add 1 day to a Datetime object

Is it possible to add a day to a Datetime variable, for example myDate contains 31/08/2008, how can I add one day to it, which will make it become 01/09/2008?

please take at look at Apex docs under Date Methods, or Datetime Methods.
There is a method called addDays().

This method will respect adding a day that might push the date to the next month.
DateTime t = DateTime.Now().AddDays(1);

08:29:18 INFO - 20080702152918.067:AnonymousBlock: line 2, column 1: 2008-07-03 15:29:18
What about subtracting a day? Is it Today().AddDays(-1) ?
Correct! Run this in your Developer Console. This will subtract 1 day from the current date and time.
DateTime newDate = DateTime.Now().AddDays(-1);
system.debug('Time = ' + newDate);