Skip to Content

TheBlogReaders.com

Salesforce.com, PHP, MySQL, Javascript, Ajax, Htacces

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

Be First!

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>

 

(2791)

Previous
Next

Leave a Reply