I have a custom field with data type "Date" and when I run a query in the dev console the date returns as expected

SELECT customfield_date__d from myobject


When I query against the custom object using a List in Apex the field in the List is now in DateTime

List<myobject> myrows = [SELECT customfield_date__d from myobject]

Debug log


If I display the field in the log (system.debug()), the results is strange; the "T" and ".000Z" are removed


2017-10-04 00:00:00

I'm not exactly clear on all the conversion going on, but the result I need is the custom field in date format


I need to compare the date to 60 days ago for all the rows in myobject and with all these conversions I"m getting stuck on how to proceed.

  • what is your current approach? where is your code? where re you stuck? as is, this might be a possible duplicate of Convert DateTime to Date
    – glls
    Commented Oct 4, 2017 at 0:52

1 Answer 1


It's really just how the system behaves. Date values are just DateTime values with a midnight component, and that's how the system debugs Date values (via String.valueOf(Date)). They all mean exactly the same thing. If you want to compare to sixty days ago, just get a date:

Date sixtyDaysAgo = Date.today().addDays(-60);
if(sixtyDaysAgo > myrows[0].customfield_date__c) {
    // was more than sixty days ago
} else {
    // sixty or less days ago

Not the answer you're looking for? Browse other questions tagged .