Salesforce Certified Application Architect

Sunday 8 November 2015

Converting DateTime to Date in Salesforce

Problem: Convert DateTime to Date 

Approach 1:

Solution: Just create a date newInstance() and pass the year,month,day from the dateTime.
Here is the Code,
1.    DateTime dt = System.now();
2.    Date myDate = date.newinstance(dt.year(), dt.month(), dt.day());
3.    System.debug('My date is-----'+myDate);
Approach 2:
Solution: Convert DateTime to Date using Date() method.

Here is the Code,
1.    DateTime dt = System.now()
2.    Date myDate= dt.date();
3.    System.debug('My date is-----'+myDate);

No comments:

Post a Comment

Salesforce Certified Application Architect & Certified Data Architecture and Management Designer Exam

How to pass Salesforce Certified Data Architecture and Management Designer Exam This exam was 1st architect exam for me. Its not that muc...