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 1


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
    @BarCotter tnx for the edit
    – dino ursic
    Jan 20, 2014 at 15:42
  • 5
    Date.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
    – RobD
    Jul 13, 2015 at 15:35

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.