I am trying to output a date type with the format yyyy-MM-dd, but. not as a string type.
I can create the string just fine.
// First I output 2018-12-01 00:00:00 as a date
currentDate = Date.today().toStartofMonth();
// Outputs 2018-12-01 as a string
firstDayOfCurrentMonth = currentDate.addMonths(i).toStartofMonth();
String currentDateString = String.valueOf(firstDayOfCurrentMonth).removeEnd('00:00:00');
However, the issue is converting that string back into the Date type using either .valueOf or .parse
// Outputs 2018-12-01 00:00:00
Date.valueOf(currentDateString);
// Outputs 2018-12-01 00:00:00
Date.valueOf(currentDateString.removeEnd(' 00:00:00'))
Date.parse(currentDateString)
// Throws error with Invalid Date : 2018-12-01
My question is, how can I convert the correctly formatted string back into the Date type without the HH:mm:SS
Edit: Just for anyone that happens to come across this in the future. I solved my issue by working with only strings, then on insert - parsed to date.