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

Salesforce Asked on January 2, 2022

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!

Related Questions

How to truncate a string to a specific length if it is longer?

4  Asked on February 10, 2021 by imajmdf


Update contact activity in Journey builder

1  Asked on February 10, 2021 by mary-jon


Hide iframe url

1  Asked on February 8, 2021 by cloudy-ritz


How can we add placeholder for lightning:InputField?

1  Asked on February 6, 2021 by aakash-poudel


LWC OSS Build Command

1  Asked on February 3, 2021 by scott-morrison


%%_PreHeader%% Personalization String

1  Asked on February 2, 2021 by victorcorey


Marketing cloud new Transactional Messaging API

1  Asked on January 30, 2021 by martijn-e


Can’t send to a list in marketing cloud?

1  Asked on January 30, 2021 by 4kaudio


Ask a Question

Get help from others!

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