Sample Code:
Visualforce Page:
<apex:page controller=”SamplePageController”>
Current Year Datetime is {!currentYearDT}<br/><br/>
Last Year Datetime is {!lastYearDT}
</apex:page>
Visualforce Page:
<apex:page controller=”SamplePageController”>
Current Year Datetime is {!currentYearDT}<br/><br/>
Last Year Datetime is {!lastYearDT}
</apex:page>
Apex Class:
public class SamplePageController {
public DateTime currentYearDT { get; set; }
public DateTime lastYearDT { get; set; }
public SamplePageController() {
currentYearDT = System.now();
lastYearDT = currentYearDT.addMonths( -12 );
}
}
Output: