How to get the Current Date and Year Using Apex Class?

System.debug(‘************ ‘ +;
System.debug(‘************ ‘ +;


************ 07/16/2014

************ 07/16/2014

How to get current year using Apex in Salesforce?

Integer Year = Date.Today().Year();


************ 2014

How to get Yesterday Date using Apex in Salesforce?

Using addDays its possible see the following piece of code:

How to get Current Fiscal Year using Apex in Salesforce?

We can get the month of your organisation Fiscal Year with this SOQL Query :

Integer orgFiscalMonth = [SELECT FiscalYearStartMonth FROM Organization].FiscalYearStartMonth;

And create a Date variable using this :
Date orgFiscalYear = Date.newinstance(, orgFiscalMonth, 1);

How to display Current Date, Month, Year in Visualforce Page?

<apex:page >
Today’s full date is: {!TODAY()}<br/> Today’s Month is: {!MONTH(TODAY())}<br/>
Number Day of the Month: {!DAY(TODAY())}<br/> Current Year: {!YEAR(TODAY())}<br/> </apex:page>


Written by 

2x Salesforce MVP | Platform Champion | 18x Salesforce Certified | MuleSoft Certified | 8x Trailhead Ranger | TechForce Services | Sydney | Australia

Leave a Reply

Your email address will not be published. Required fields are marked *