How to Converting DateTime to Date in Salesforce?

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

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.

DateTime dt = System.now()

Date d = dt.date();

System.debug('Print Date:' + d);


Follow Us

Posted By : Sudeer Kamat Date :

view_module Related

label Labels

Comments 0