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.

closed as off-topic by glls, Santanu Boral, Ratan Paul, Raul, Samuel Dare Oct 4 '17 at 10:30

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on problems in code you've written must describe the specific problem and include valid code to reproduce it. For help writing short, self-contained syntactically-valid examples, see: SSCCE.org" – glls, Santanu Boral, Ratan Paul, Raul, Samuel Dare
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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 Oct 4 '17 at 0:52

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 or ask your own question.