You need to sign in to do that
Don't have an account?
David Picksley
String ('yyyy-MM-dd') to date using date.parse returns ('yyyy-MM-dd hh:MM:ss')
Hi All,
I am trying to output a date type of yyyy-MM-dd, not as a string. I can create the correctly formatted string and insert that into a set.
However, the issue is converting that string back into the Date type using either .valueOf or .parse
My question is, how can I convert the correctly formatted string back into the Date type?
Many thanks!!
I am trying to output a date type of yyyy-MM-dd, not as a string. I can create the correctly formatted string and insert that into a set.
currentDate = Date.today().toStartofMonth(); // Outputs 2018-12-01 00:00:00 firstDayOfCurrentMonth = currentDate.addMonths(i).toStartofMonth(); String currentDateString = String.valueOf(firstDayOfCurrentMonth).removeEnd(' 00:00:00'); // Outputs 2018-12-01 as a string
However, the issue is converting that string back into the Date type using either .valueOf or .parse
Date.valueOf(currentDateString); // Outputs 2018-12-01 00:00:00 Date.valueOf(currentDateString.removeEnd(' 00:00:00')) // Outputs 2018-12-01 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?
Many thanks!!
Try using Date.valueOf method.Please find below a piece of code to check :
system.debug('Date : + Date.ValueOf('2018-12-01 14:05:07'));
Cheers!!!