TransWikia.com

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

Salesforce Asked on January 2, 2022

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.

One 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.

Answered by sfdcfox on January 2, 2022

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP