function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Faizan Ali 24Faizan Ali 24 

Date string format

Hi All,

I want to change the format of my date. Currently, the format is in yyyy-MM-dd but I want it to be like 12th December 2020.

My apex code is currently:

currentDateString = string.valueOf(Date.today());

And in my visualforce page it is:

<apex:outputLabel id="currentDateString" style="color:white;font-size:26px;font-weight:bold">{!currentDateString}</apex:outputLabel>
Best Answer chosen by Faizan Ali 24
ravi soniravi soni
Hi Faizan,
Try this following Way
DateTime dt = Date.today();
String day = string.valueOf(Date.today().day());
string Month = dt.format('MMMM');
string Year = dt.format('YYYY');

system.debug('String Date=====> ' + day + 'th ' + Month + ' '+ Year);

Let me know, if it's helps you and mark the best of this answer so that it can help to others.
Thank You

All Answers

SwethaSwetha (Salesforce Developers) 
HI Faizan,
Looks like there is no standard function in salesforce that does this conversion to ddth mmm,yyyy format. The below article is not in context of salesforce but would serve as a pseudo code to implement the logic

https://stackoverflow.com/questions/37272514/change-date-format-to-ddth-mmm-yyyy 

Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you
ravi soniravi soni
Hi Faizan,
Try this following Way
DateTime dt = Date.today();
String day = string.valueOf(Date.today().day());
string Month = dt.format('MMMM');
string Year = dt.format('YYYY');

system.debug('String Date=====> ' + day + 'th ' + Month + ' '+ Year);

Let me know, if it's helps you and mark the best of this answer so that it can help to others.
Thank You
This was selected as the best answer