Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Date Time format - JavaScript

Posted on by 884

Hi -
I have a datetime field in which I'm using in a JavaScript function:

function getDate()
{
valu :- /Date(1509696000000)/ get crm datetime field Fri Nov 03 2017 13:30:00 GMT+0530

var date =
eval('new ' +
value.replace("/", "").replace("/", ""));
return date.format('yyyy-MM-dd hh:mm:ss tt');
alert (date)
}

The alert displays the the format of the field as this: date = 11/4/2017 1:30 PM

I need to reformat the result to show as this same value time(11/4/2017 8:00 AM) but current I got value (11/4/2017 1:30 PM) I think (plus + 5.30 hour add), so I can use it in a further part of the function.
Does anyone know how to do this in the JavaScript function?
Thanks,

*This post is locked for comments

  • CRM Develope Profile Picture
    CRM Develope 884 on at
    RE: Date Time format - JavaScript

    Thanks Francesco Picchi

    It's working fine

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Date Time format - JavaScript

    Hi CRM Developer,

    you could try with moment library:

    https://momentjs.com/ 

    using the following code:

    moment.tz.setDefault("America/New_York"); // <-- put here your timezone
    date = moment(yourdatestring, "MM/DD/YYYY HH:mm a").tz("UTC");

    Please let me know.

    If you found the answer helpful, please mark as Verified 

    Join my network on LinkedIn      Follow me on Twitter 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • shivaram Profile Picture
    shivaram 3,315 on at
    RE: Date Time format - JavaScript

    Hi,

    you entered Time as 13:30 (or you gave date value as like that). if you want 8'o clock just substract accodingly..

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans