Thursday, 10 March 2016

How to Parse date in SFDC?

Date format used to vary from system to system.

In SFDC it is like YYYY-MM-DD -2016-03-10 00:00:00

Lets say date format is DD/MM/YYYY in other system, how will we store such date foramt ?

String s = '15/08/2014';
date dt = Date.Parse(s);
System.debug('Printing--today date -'+system.today());

System.debug('Printing---'+dt);

Out put will be

11:25:10.11 (12471791)|USER_DEBUG|[3]|DEBUG|Printing--today date -2016-03-10 00:00:00
11:25:10.11 (12560905)|USER_DEBUG|[5]|DEBUG|Printing---2014-08-15 00:00:00


3 comments:

Unknown said...

Hi,

I run the same in execute anonymus block but i am getting error as invalid date please suggest

Unknown said...

i am gettin error like Invalid date: 15/08/2014

Asish Kumar Behera said...

Please let me know what is your date format.In the workbench please print like below.
System.debug('Printing---'+system.now());