1

i want to convert

2015-07-27 00:00:00

into

mm/dd/yyyy

format in salesforce(Apex).

i have search the net do not get any proper way.pls help.

Thanks..

2

You could try extracting the date part in a String variable and then create a new instance of Date with your format.

String ExtractedDate = '2015-07-27';

list<String> lstSplitDate = ExtractedDate.split('-');
Date myDate = date.newinstance(Integer.valueOf(lstSplitDate[0]), Integer.valueOf(lstSplitDate[1]), Integer.valueOf(lstSplitDate[2]));

Home this will help you ;)

| improve this answer | |
2

You can use DateTime.format method - https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_datetime.htm#apex_System_Datetime_format_2

| improve this answer | |
2

This sounds like SQL date format from ISO 9075:

YYYY-MM-DD HH:MM:SS

Apex Datetime.valueOfGmt(string) can inhale it:

Datetime midnight = Datetime.valueOfGmt('2015-07-27 00:00:00');

Then you can use Datetime.formatGmt(format) to output it:

midnight.formatGmt('MM/dd/yy'); //gives you "07/27/15"

Be careful with the GMT input and output to avoid moving off the exact date boundary. Manual formatting should be used sparingly; instead the running user's locale setting should be respected.

| improve this answer | |

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.