web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Setting Date and time field using JavaScript

(0) ShareShare
ReportReport
Posted on by 161

I have to set a field of type Date and time with  current date and time + 5 hours how can I do that with JavaScript? Please provide solution.

thanks in advance

*This post is locked for comments

I have the same question (0)
  • minohimself Profile Picture
    2 on at

    var currentDateTime = new Date();

    Xrm.Page.getAttribute("xyz").setValue(currentDateTime);

  • minohimself Profile Picture
    2 on at

    new Date(); is the Client date not server date

  • Nagaraj M Profile Picture
    161 on at

    Hi Milan

    I have to add  5 hours more to the CurrentDateTime how can i do that?

  • minohimself Profile Picture
    2 on at

    new Date().addHours(5)

  • Suggested answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    with JavaScript you can get only the client datetime, not the server one.

    the code to add 5 hours is

    var currentDate = new Date();
    currentDate.setHours(currentDate.getHours()+5);
    Xrm.Page.getAttribute("field").setValue(currentDate);


  • Community Member Profile Picture
    on at

    Hi, I have two date time fields.

    In the first field, if the date is set, then in the second date time field, the date should be automatically populated

    with this format.

    Field 1: 09/30/2016

    Result of Field 2: 09/29/2017.

    I have set the year but unable to set the Date.

    So please help me with your suggestions.

  • DineshRaja Profile Picture
    on at

    how to do this..many time i tried this using javascript but i will get  error..

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Dinesh,

    Try setting the field by using the following:

           Xrm.Page.getAttribute('nameOfDateTimeField').setValue(new Date());

  • Community Member Profile Picture
    on at

    Hi,

    please refere to the following code

    function Notify() {
    var currentDate = new Date();

    currentDate.setHours(currentDate.getHours() + 5);
    alert(currentDate );
    Xrm.Page.getAttribute("scheduledend").setValue(currentDate);

    }

  • Dynamics_Alok Profile Picture
    1,746 on at

    User can get User Time Zone  using WebAPI call for UserSettings and then he can adjust his System timezone value accordingly .

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans