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.

1 Answer 1

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()));
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .