You need to sign in to do that
Don't have an account?
smriti sharan19
Issue while converting date in yyyy-mm-dd Format
I am trying to convert date in yyyy-mm-dd format but I am getting result in yyyy-dd-mm format.
Initial Value of DateField:
datetimeinquiry=2019-06-11 00:00:00
Tried newInstance
convertToStr = DateTime.newInstance(datetimeinquiry.year(),datetimeinquiry.month(),datetimeinquiry.day()+1).format('yyyy-MM-dd');
Result:2019-06-11
Tried formatGMT:
system.debug('formatGMT: '+datetimeinquiry.formatGMT('yyyy-MM-dd'));
Result:2019-06-11
Initial Value of DateField:
datetimeinquiry=2019-06-11 00:00:00
Tried newInstance
convertToStr = DateTime.newInstance(datetimeinquiry.year(),datetimeinquiry.month(),datetimeinquiry.day()+1).format('yyyy-MM-dd');
Result:2019-06-11
Tried formatGMT:
system.debug('formatGMT: '+datetimeinquiry.formatGMT('yyyy-MM-dd'));
Result:2019-06-11
I have tried your code and getting the result in yyyy-mm-dd format.
Your query is answered above check it.
Example Code Snippet:-
Datetime d1 = System.now();
String sFormat = d1.format('yyyy/MM/dd HH:mm:ss');
String sFormatGMT = d1.formatGMT('yyyy/MM/dd HH:mm:ss');
System.debug(d1); // DEBUG|2020-01-06 11:13:21 because it always shows the datetime in UTC
System.debug(sFormat); // DEBUG|2020/01/06 12:13:21 because I'm at GMT+1
System.debug(sFormatGMT); // DEBUG|2020/01/06 11:13:21 because I forced the GMT time zone
https://salesforce.stackexchange.com/questions/80214/issue-with-datetime-formatmm-dd-yyyy
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.