function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
TehNrdTehNrd 

Is there a DateTime to Date method?

I look through the documentation and didn't see a system method that converts a date time field to a date. There is one for formula fields but is there one for Apex?

Sorry if I missed it.


Message Edited by TehNrd on 11-06-2007 01:47 PM

Ron HessRon Hess
i think you would just create a date newInstance() and pass in just the year,month,day from the dateTime object.


        datetime t = System.now();
        date d = Date.newInstance(t.year(),t.month(),t.day());
        system.debug(t);
        system.debug(d);


20071106232925.784:Class.time.getTime: line 14, column 9: 2007-11-06 23:29:25
20071106232925.784:Class.time.getTime: line 15, column 9: 2007-11-06 00:00:00
TehNrdTehNrd
Thanks. That's what I ended up doing. Looks like something to add to the Utility class.
SudhanwaSudhanwa

Adding to this is a problem...

 

I have a date field which should have the value of addition of 2 fields. One of these fields is a datetime and the other one is an integer.

 

What I did was...

 

datetime chkOutStamp = currentObj.Check_Out_Timestamp__c;

 date newChkOutStamp = date.NewInstance(chkOutStamp.year(),chkOutStamp.month(),chkOutStamp.day());
  currentObj.Return_Due_Date__c = newChkOutStamp + parentObjList[0].Checkout_Days__c;

 

 

Return_Due_Date__c => date field

Check_Out_Timestamp__c => datetime field

 Checkout_Days__c => Integer field (A formula field which returns a number).

 

I get an error for the third line saying

"Error: Compile Error: Date arithmetic expressions must use Integer or Long arguments at line ...."

 

I searched for this error in the community but didnt find any help. Does any of you have an idea?

 

Thanks,

Sudhanwa.