You need to sign in to do that
Don't have an account?
Vinothini Rajan
datetime.formatGMT() for today's date returns next year
Hello All,
Below datetime formatting suddenly not working properly. Below lines returns next year 2022.
DateTime lstUptDate = DateTime.newInstanceGmt(Date.today(), Time.newInstance(0, 0, 0, 0));
System.debug(lstUptDate.formatGMT('YYYY-MM-dd\'T00:00:00\''));
20:12:14.1 (2360027)|USER_DEBUG|[2]|DEBUG|2022-12-29T00:00:00
Below datetime formatting suddenly not working properly. Below lines returns next year 2022.
DateTime lstUptDate = DateTime.newInstanceGmt(Date.today(), Time.newInstance(0, 0, 0, 0));
System.debug(lstUptDate.formatGMT('YYYY-MM-dd\'T00:00:00\''));
20:12:14.1 (2360027)|USER_DEBUG|[2]|DEBUG|2022-12-29T00:00:00
change YYYY to yyyy.
it worked.
All Answers
Please try this code
DateTime lstUptDate = DateTime.newInstanceGmt(Date.today(), Time.newInstance(0, 0, 0, 0));
system.debug('formatted date=='+lstUptDate.formatLong());
Please refer to the link below:
https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_datetime.htm#apex_System_Datetime_formatGmt
Also please try
DateTime lstUptDate = DateTime.newInstanceGmt(Date.today(), Time.newInstance(0, 0, 0, 0));
System.debug(lstUptDate.formatGMT('EEE, MMM d yyyy HH:mm:ss'));
System.debug(lstUptDate.formatGMT('MMM d yyyy HH:mm:ss'));
System.debug(lstUptDate.formatGMT('MM dd yyyy HH:mm:ss'));
System.debug(lstUptDate.formatGMT('MM-dd-yyyy HH:mm:ss'));
all these are working.
Thanks
Vijaya Donepudi.
Thanks for your reply. I need it the format YYYY-MM-dd.
It was working before from 25th dec it seems to be picking up with year that's 2022.
change YYYY to yyyy.
it worked.
YYYY' is the calendar year for the WEEK that the day falls in
'yyyy' is the calendar year as of that DAY.