Print this page

Converting DATE to DATETIME

Knowledge Article Number 000194217
Description Converting DATE to DATETIME
Resolution To convert DATE to DATETIME you can make use of newInstanceGmt(Date, Time) method: 
--------------------------------------------------------------------------------------------- 
Constructs a DateTime from the specified date and time in the GMT time zone. 

Signature: 
public static Datetime newInstanceGmt(Date dt, Time tm) 

Parameters :
dt Type: Date 
tm Type: Time 

Return Value: 
Type: Datetime 
--------------------------------------------------------------------------------------------- 
Reference: https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_datetime.htm

Here is a snippet of Apex Code that shows how to take the Year, Month, and Day of a date object and convert it to a dateTime object. 
--------------------------------------------------------------------------------------------- 
Date dToday = System.Today(); 
Datetime dt = datetime.newInstance(dToday.year(), dToday.month(),dToday.day()); 
--------------------------------------------------------------------------------------------- 
Reference: https://developer.salesforce.com/forums/ForumsMain?id=906F00000008kuMIAQ




promote demote