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

System.debug(‘************ ‘ + system.today().format());
System.debug(‘************ ‘ + date.today().format());

Output:-

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

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

How to get current year using Apex in Salesforce?

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

Output:-

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

How to get Yesterday Date using Apex in Salesforce?

Using addDays its possible see the following piece of code:
Date.today().addDays(-1)

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(system.today().year(), 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>

 

(2833)

Written by 

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

Leave a Reply