I have my date in following format: 2014-01-20 00:00:00 I want it in the following format 1/20/2014(mm/dd/yyyy) But i want it as date variable not as a string.
1 Answer
You already have a date 'as a date', not as a string. The format you are talking about (2014-01-20 00:00:00) is just a visual representation of a value contained in variable of a DateTime type. If you want the date to appear in the specified format (1/20/2014), just output it using format() method:
Datetime yourDate = Datetime.now();
String dateOutput = yourDate.format('dd/MM/yyyy');
-
1
-
5Date.format(string format) - seems to no longer be supported. It looks like there is only a default format() with no parameters that returns a value based on the user locale - sforce.co/1DbYQ5O– RobDCommented Jul 13, 2015 at 15:35