Skip to main content
Post a question

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

change date format on the field

Posted on 10 Apr 2018 15:51:38 by 815

Hi,

I have created 2 fields. 1 set as "System Shipped Date" date only field  and another 1 as "Warranty Status" calculated field.

Date format is showing perfectly and the requirement is need to change the display format on the field.

Instead of showing as 4/10/2018 it should show as April 10 2018

Please note this requirement is only for that field not for the entire system.

PFA

7206.Untitled1.png

Regards

Faisal

 

*This post is locked for comments

  • Syed_Faisal Profile Picture
    Syed_Faisal 815 on 11 Apr 2018 at 14:57:58
    RE: change date format on the field

    Thanks a lot, Goutham !

    It works.

    Regards

    Faisal

  • Verified answer
    gdas Profile Picture
    gdas 50,085 on 10 Apr 2018 at 19:45:15
    RE: change date format on the field

    Hi Faisal,

    Its normal this is because you are setting current date so what you need to do following . Just instead of current date get the date from your old field.

    1. function ChangeDateFormat() {
    2.  
    3. var oldDate = Xrm.Page.getAttribute("DateFieldName").getValue(); //Replace the field name with the old date field
    4. var d = new Date(oldDate);
    5. //var d = new Date();
    6. var month = new Array();
    7. month[0] = "January";
    8. month[1] = "February";
    9. month[2] = "March";
    10. month[3] = "April";
    11. month[4] = "May";
    12. month[5] = "June";
    13. month[6] = "July";
    14. month[7] = "August";
    15. month[8] = "September";
    16. month[9] = "October";
    17. month[10] = "November";
    18. month[11] = "December";
    19. var Month = month[d.getMonth()];
    20. var Day = d.getDate();
    21. var Year = d.getFullYear();
    22. var datewithFormat = Month + " " + Day + " " + Year;
    23. Xrm.Page.getAttribute("new_warrantystatus").setValue(datewithFormat);
    24.  
    25. }


  • Syed_Faisal Profile Picture
    Syed_Faisal 815 on 10 Apr 2018 at 17:41:10
    RE: change date format on the field

    We don't want to change the existing data, just want to change the display format

  • Syed_Faisal Profile Picture
    Syed_Faisal 815 on 10 Apr 2018 at 17:40:09
    RE: change date format on the field

    Hi Goutham,

    Code is working fine but we need to change something on the code.

    Issue here is it is setting up today's date but we actually want the date which is already exist on the field only that format needs to change.

    What is happening is, when we run the code the existing OLD date is also getting change and set to today's date.

    Could you please help?

  • Syed_Faisal Profile Picture
    Syed_Faisal 815 on 10 Apr 2018 at 17:26:09
    RE: change date format on the field

    Hi Goutham,

    Thanks for the code, it is working absolutely perfect. 

    4604.Untitled1.png

    Regards

    Faisal

  • Verified answer
    gdas Profile Picture
    gdas 50,085 on 10 Apr 2018 at 16:57:38
    RE: change date format on the field

    Hi Sayed ,

    Here you go -

    1. function ChangeDateFormat() {
    2. var d = new Date();
    3. var month = new Array();
    4. month[0] = "January";
    5. month[1] = "February";
    6. month[2] = "March";
    7. month[3] = "April";
    8. month[4] = "May";
    9. month[5] = "June";
    10. month[6] = "July";
    11. month[7] = "August";
    12. month[8] = "September";
    13. month[9] = "October";
    14. month[10] = "November";
    15. month[11] = "December";
    16. var Month = month[d.getMonth()];
    17. var Day = d.getDate();
    18. var Year = d.getFullYear();
    19. var datewithFormat = Month + " " + Day + " " + Year;
    20. Xrm.Page.getAttribute("new_warrantystatus").setValue(datewithFormat);
    21.  
    22. }


  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on 10 Apr 2018 at 16:48:23
    RE: change date format on the field

    Hello,

    Here is code that you can use:

    var d = new Date();

    var monthes = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

    var result = monthes[d.getMonth()] + " " + d.getDate() + " " + d.getFullYear();

    Xrm.Page.getAttribute("your customer string field").setValue(result);

    Good luck.

  • gdas Profile Picture
    gdas 50,085 on 10 Apr 2018 at 16:41:18
    RE: change date format on the field

    ok let me check will update in a while.

  • Syed_Faisal Profile Picture
    Syed_Faisal 815 on 10 Apr 2018 at 16:31:30
    RE: change date format on the field

    Hi Goutam,

    Could you help me with the code.

    function ChangeDateFormat(){

    Xrm.Page.getAttribute("new_warrantystatus").setValue(Date.now());

    }

    what could be setvalue ? Month Date Year

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on 10 Apr 2018 at 16:24:31
    RE: change date format on the field

    Hi Sayed,

    Create a single line text field and in onload get the data from original field and change the format using JS and set the value to new field. Hide the original field .

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans