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 

I am Sakthivel Madesh, a certified Salesforce Advanced Developer & Administrator working on Salesforce Technology since 2011. I am currently working in Techforce Services as Sr. Salesforce Developer. I have worked on multiple technologies Like PHP, Java, Salesforce, I am very passionate about Salesforce and to earn 15x Salesforce Certification. I love Trailhead for learning Salesforce Skill and Become a Trailhead 5x Ranger too. I Love to Learn & Share my Salesforce knowledge to Salesforce Learners/Beginner using My Blog and Salesforce Community.

Leave a Reply

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