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
aottaruaottaru 

Date Format function

Hello everyone,

I have been using a the following date format function to for format my date in the following format 'October 19, 2015'

The function has been working well but today we jsut found out that if the date selected is 2015-31-12, It is being formated as 'December 30, 2016' instead of 'December 30, 2015'

Does anyone knows what is causing this? 

This is how I am calling the function dateTimeScheduled.format('MMMM d, YYYY');
Best Answer chosen by aottaru
Shashi PatowaryShashi Patowary
Hi,

I just put year notation in small instead of caps and it worked
private String formatDate(Date dateIn){
        DateTime dateTimeScheduled = DateTime.newInstance(dateIn,Time.newInstance(0,0,0,0));
        return dateTimeScheduled.format('MMMM d, yyyy');
    }
I don't know what logic that SFDC has implemented but usually day (d) and year (yyyy) are used in small letter only for date format.

Please let me know if it helped.

Regards,
Shashi
 

All Answers

Shashi PatowaryShashi Patowary
Hi,

Probably you built a custom function to format a date.Please share your custom code.I will try to help you.

Regards,
Shashi
aottaruaottaru
Thank you Shashi, Please see my code below:

private String formatDate(Date dateIn){
        DateTime dateTimeScheduled = DateTime.newInstance(dateIn,Time.newInstance(0,0,0,0));
        return dateTimeScheduled.format('MMMM d, YYYY');
    }

Please let me know if this helps. 
Keshab AcharyaKeshab Acharya
There could be some other issue i can tell you the above code is perfectly fine.

 
Shashi PatowaryShashi Patowary
Hi,

I just put year notation in small instead of caps and it worked
private String formatDate(Date dateIn){
        DateTime dateTimeScheduled = DateTime.newInstance(dateIn,Time.newInstance(0,0,0,0));
        return dateTimeScheduled.format('MMMM d, yyyy');
    }
I don't know what logic that SFDC has implemented but usually day (d) and year (yyyy) are used in small letter only for date format.

Please let me know if it helped.

Regards,
Shashi
 
This was selected as the best answer
aottaruaottaru
Thank you Shashi, using lower case solved the issue.