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

OAuth2 token request failing

4  Asked on December 14, 2021 by varun


Invalid type: Schema.SObject

1  Asked on December 14, 2021 by lalitha-rallabandi


Assigning field value from set help

1  Asked on December 14, 2021 by bblackinton


refresh token not update access token

2  Asked on December 12, 2021 by sergey-bondarenko


SFMC MobilePush that uses SFDC ContactID as SFMC ContactKey

1  Asked on December 12, 2021 by juliehurtz


Ask a Question

Get help from others!

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