locked
Date field in CRM 2011 RRS feed

  • Question

  • I have a date filed in crm and when I do a laert it

    returns this "Thu Jul 26 00:00:00 EDT 2012"

    How do I convert this to "mm/dd/yyyy"

    Wednesday, September 26, 2012 5:25 PM

Answers

  • following code for the same..

    var dtStartDate = new Date(crmForm.all.msa_startdate.DataValue); //For CRM 4.0
    var dtStartDate = new Date(Xrm.Page.getAttribute("followupby").getValue()); //For CRM 2011
    
    var iMonth = dtDate.getMonth() + 1;
    var iDay = dtDate.getDate();
    var iYear = dtDate.getFullYear();
    
    string newDateMMDDYYYY =  iMonth + "/" + iDay + "/" + iYear;
    
    alert(newDateMMDDYYYY);


    MayankP
    My Blog
    Follow Me on Twitter

    • Marked as answer by Nandhini12 Thursday, September 27, 2012 2:26 PM
    Thursday, September 27, 2012 8:54 AM

All replies

  • Try something like this:

    function AlertDate() {
        var d = Xrm.Page.getAttribute("createdon").getValue();
        alert(padLeft(d.getMonth() + 1) + '/' + padLeft(d.getDate()) + '/' + d.getFullYear());
    }
    
    function padLeft(n) {
        n = '' + n;
        if (n.length == 1) {
            return '0' + n;
        }
        else {
            return n;
        }
    }


    Jason Lattimer


    Wednesday, September 26, 2012 5:48 PM
    Moderator
  • Thanks will try that.

    also

    when I try to set the value of the text field I am getting an error saying "unable to get property of set value is null"

    function datevalue()

    {

       

    var  date1 = Xrm.Page.getAttribute("wsb_functiondate").getValue(); --- this is a date field

    var  time1 = Xrm.Page.getAttribute("wsb_starttime").getValue(); --- this is a text filed

    var  datetime1 = date1 + " "+ time1;

        Xrm.Page.getAttribute(

    "wsb_schedulestarttime").setValue(datetime1);}



    • Edited by Nandhini12 Wednesday, September 26, 2012 6:25 PM
    Wednesday, September 26, 2012 6:23 PM
  • hello nadhini

    use alert and check the values for date1 and time1

    for debug the script in the internet explorer


    ms crm

    Wednesday, September 26, 2012 6:54 PM
  • I get it like "Thu Jul 26 00:00:00 EDT 2012 2:00pm"

    I enter the time as 2.00pm in the text field.

    Wednesday, September 26, 2012 11:36 PM
  • following code for the same..

    var dtStartDate = new Date(crmForm.all.msa_startdate.DataValue); //For CRM 4.0
    var dtStartDate = new Date(Xrm.Page.getAttribute("followupby").getValue()); //For CRM 2011
    
    var iMonth = dtDate.getMonth() + 1;
    var iDay = dtDate.getDate();
    var iYear = dtDate.getFullYear();
    
    string newDateMMDDYYYY =  iMonth + "/" + iDay + "/" + iYear;
    
    alert(newDateMMDDYYYY);


    MayankP
    My Blog
    Follow Me on Twitter

    • Marked as answer by Nandhini12 Thursday, September 27, 2012 2:26 PM
    Thursday, September 27, 2012 8:54 AM
  • Thanks !!
    Thursday, September 27, 2012 2:26 PM
  • Hi,

    try this simple JS

    var  date1 = Xrm.Page.getAttribute("wsb_functiondate").getValue();

    date1= date1.format("mm/dd/yyyy");

    Thursday, September 27, 2012 2:53 PM