[SalesForce] How to remove the time 00:00:00 from a date format and still maintain the date type

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.

Best Answer

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.

Related Topic