locked
Time field to be formatted RRS feed

  • Question

  • I have a crm time text field that the user enters 2pm, 2.00pm, 2.30pm etc.

    I need to format that into "00:00:00" in this format.

    Thursday, September 27, 2012 2:28 PM

Answers

  • hi nandini,

    you can use this below function

    function changeToDate()
    
    {
    
    var date="";
    
    var Value=Xrm.Page.getAttribute("yourtextfield").getValue();
    
    var delimited=Value.split(':');
    
    if(delimited.length>0)
    
    {
    
     date=Value.split[0]+":"+Value.split[1] !=null?Value.split[1]:"00"+Value.split[2] !=null?Value.split[2]:"00";
    
    }
    
    else
    
    date=delimited+":00"+":00";
    
    Xrm.Page.getAttribute("yourtextfield").setValue(date);
    
    }


    Please don't forget to Vote and marked as answer If this post answers your question or was helpful, please click "Mark As Answer" on the post and "Mark as Helpful" Be wise


    • Edited by anwar.noori Friday, September 28, 2012 7:41 AM
    • Marked as answer by Nandhini12 Monday, October 1, 2012 5:44 PM
    Friday, September 28, 2012 7:41 AM

All replies

  • Hi Nandini,

    You can Write a js on change of this text field and check if its been entered correctly,please try this

    function fnFormatTime()

    {

    varn="";

    var k=Xrm.Page.getAttribute("yourtextfield").getValue();

    var delimited=k.split(':');

    if(delimited.length>0)

    {

     n=k.split[0]+":"+k.split[1] !=null?k.split[1]:"00"+k.split[2] !=null?k.split[2]:"00";

    }

    else

    n=delimited+":00"+":00";

    Xrm.Page.getAttribute("yourtextfield").setValue(n);

    }

    • Proposed as answer by mkkarthik Thursday, September 27, 2012 5:23 PM
    Thursday, September 27, 2012 5:22 PM
  • hi nandini,

    you can use this below function

    function changeToDate()
    
    {
    
    var date="";
    
    var Value=Xrm.Page.getAttribute("yourtextfield").getValue();
    
    var delimited=Value.split(':');
    
    if(delimited.length>0)
    
    {
    
     date=Value.split[0]+":"+Value.split[1] !=null?Value.split[1]:"00"+Value.split[2] !=null?Value.split[2]:"00";
    
    }
    
    else
    
    date=delimited+":00"+":00";
    
    Xrm.Page.getAttribute("yourtextfield").setValue(date);
    
    }


    Please don't forget to Vote and marked as answer If this post answers your question or was helpful, please click "Mark As Answer" on the post and "Mark as Helpful" Be wise


    • Edited by anwar.noori Friday, September 28, 2012 7:41 AM
    • Marked as answer by Nandhini12 Monday, October 1, 2012 5:44 PM
    Friday, September 28, 2012 7:41 AM