0

PROBLEM: I converted a string to Date format. Eg: String dateToParse = year+'-'+month1+'-'+day; Date ds = Date.parse(dateToParse); OUTPUT: 2020-07-24 00:00:00 (output is a Date type variable)

Expected: OUTPUT: 2020-07-24 (without the time 00:00:00, still maintaining the Date type variable) Note: I know that using ds.format() would give me the expected output, but this converts it into a string. I want to maintain the date type format.

0

Date types are intrinsically DateTime types with the time factor set to 00:00:00. You can't have a Date that does not have a time factor. What you're asking for is impossible.

| improve this answer | |
  • Thank you for clearing that! Can i use the current date format in ds date variable to query something else. For e.g. Select Name, OrderNumber__c from Opportunity where CloseDate =: ds – Raj Jul 24 at 18:56
  • @Raj Yes, that's perfectly fine. – sfdcfox Jul 24 at 18:57
  • Thank you again – Raj Jul 24 at 19:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.