Ticker

6/recent/ticker-posts

Converting DateTime to Date in Salesforce

 



Converting DateTime to Date in Salesforce



Solution 1: Create a date newInstance() and pass the Year, Month, and Day from the DateTime.

1
2
3
DateTime dt = System.now();
Date d = Date.newInstance(dt.year(), dt.month(), dt.day());
System.debug('Print Date:' + d);

Solution 2: Get date from the DateTime using Date() method.

1
2
3
DateTime dt = System.now()
Date d = dt.date();
System.debug('Print Date:' + d);




Post a Comment

0 Comments