Converting Date to DateTime

I think the simplest method for you to use will be something like the following:

Integer d = Due_Date__c.day();
Integer mo = Due_Date__c.month();
Integer yr = Due_Date__c.year();

DateTime DT = DateTime.newInstance(yr, mo, d);

If you want to keep the 11:59:59 in your local time zone, change the last line as follows:

DateTime DT = DateTime.newInstance(yr, mo, d, 11, 59, 59);

The most simple way to convert a date to a date time, with a time component of 00:00:00.0, is to simply assign a Date to a Datetime variable, or to cast a Date to a Datetime. For example, the following works:

Date today = Date.today();
Datetime todayDateTime = today; // Implicit cast
System.debug('Today is ' + todayDateTime);
System.debug('Today is also ' + (Datetime) today); // Explicit cast

The output would be like:

...|DEBUG|Today is 2017-10-18 00:00:00
...|DEBUG|Today is also 2017-10-18 00:00:00

I don't know which API version introduced this capability, but it is there from v39 at least.

NOTE: This results in a Datetime value in UTC, not in the current user's time zone.

Tags:

Date

Apex