+ Start a Discussion
JamesSSJamesSS 

How to get today date in apex class?

My input:

System.debug('Date.today();************ ' + date.today());

 

Output:

Date.today();************  2013-06-07 00:00:00

 

expected output:

Date.today();************  2013-06-07 

 

Is possible to get my expected output?

Best Answer chosen by Admin (Salesforce Developers) 
sandeep@Salesforcesandeep@Salesforce

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

 

Both will work like 

 

************ 07/06/2013

************ 07/06/2013

All Answers

Gunish Rai ChawlaGunish Rai Chawla
You would have to use, Date Methods to extract, Month, Year and Date, and re-concatenate all of these to form a string.
JamesSSJamesSS

Thanks Gunish.

Please provide some example for that

sandeep@Salesforcesandeep@Salesforce

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

 

Both will work like 

 

************ 07/06/2013

************ 07/06/2013

This was selected as the best answer
Navaprasad Reddy AndeNavaprasad Reddy Ande
Please try this

DateTime todaysDate = System.today();
String todaysDateStr = todaysDate.format('yyyy-MM-dd');
System.debug(todaysDateStr);

Please mark this as best answer if this works for you.