2

I'm sending an http callout with a body that requires todays date formatted as 'YYYY-MM-DD', does anyone know how I can change the format of the date? I tried

Date todaysdate = Date.today(); string dateoutput = todaysdate.format('YYYY-MM-DD');

Does anyone know how I can do this? Thanks.

2

There are several ways of getting it. format() returns the date Date as a string using the locale of the context user. However, in the US that would be in dd/mm/yyyy, which isn't what you're looking for. consequently, I'd recommend the following unless you wanted to use Date-Time methods based on Now().

string dateoutput = string.valueOf(year(today())) + '-' + string.valueOf(month(today())) + '-' + string.valueOf(day(today()));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.