locked
datetime format RRS feed

  • Question

  • Hi,

    I have an entity that has a datetime field and lookup field.

    If a choose a date, I need to check whether that date is already used with the same lookup value.

    So using javascript via webservice I return all the date values assosiated with that lookup value. The next step is to check whether the returned value is equal with the value in the date field.

    However, the webservice returns the value in  2011-01-12T00:00:00-00:00 format,

    and crmForm.all.new_date.DataValue returns the value in Wed Jan 5 00:00:00 UTC+0100 2011 format, so I can't compare them.

    Any suggestion on how to solve this?

    Thanks,

     

     

    Wednesday, January 12, 2011 8:01 AM

Answers

  • Hi,

    if you check my method it takes two string input str1 and str2 so I suggest you pass your relevant dates as string in str1 and str2 respectively.

    then I do following line..

    var d1 = new Date(str1);
    var d2 = new Date(str2);

    above code line will create new Java script dates using datestring you passed so these two new dates will be in same format and you should be able to compare them...

    hope this helps..


    MayankP
    My Blog
    Follow Me on Twitter
    • Marked as answer by mimamar Thursday, January 13, 2011 10:32 AM
    Thursday, January 13, 2011 9:40 AM
    Answerer

All replies

  • Hello,

    You could achieve this using following example code...
    Hope this helps...

    function IsLesserDate(str1, str2) 
    {
    var d1 = new Date(str1);
    var d2 = new Date(str2);			
    
    if(d1.valueOf() < d2.valueOf())
     { 
    return true; 
     } 
     else 
     { 
    return false; 
     }
    }
    
    //calling above function with your dates as perameters
    if(IsLesserDate(<<first date>>,<<second date>>))
    {					 returnValue = true;
    }	
    else
    {
    alert('second date should be greater than first date');
    returnValue = false; 
    }			 
    

    MayankP
    My Blog
    Follow Me on Twitter
    Wednesday, January 12, 2011 9:42 AM
    Answerer
  • Hi Madma,

    you can format the related fields using the java script like

    var value=crmForm.all.new_date.DataValue;

    var year = value.getYear().toString();
    var month = (value.getMonth() + 1).toString();
    var dayOfMonth = value.getDate().toString();

     

    or exact answer check the following link,

    http://mscrm4ever.blogspot.com/2009/09/formatting-crm-datetime-field.html

     

    Regards,

    Wednesday, January 12, 2011 9:45 AM
  • Thanx for your replies... :) I really appriciate you trying to help me.

    MayankP: my problem is not the coparing method itself, it's the format in which I get the dates that I should compare. :)

    Ercan Top: Thanx for your answer. However I have a problem with the T00:00:00-00:00 part. I can get only 00:00:00. :)

    Is there a way to convert this Wed Jan 5 00:00:00 UTC+0100 2011  to  this  2011-01-12T00:00:00-00:00 ? 

    I really need help on this.

    Thursday, January 13, 2011 7:35 AM
  • Hi,

    if you check my method it takes two string input str1 and str2 so I suggest you pass your relevant dates as string in str1 and str2 respectively.

    then I do following line..

    var d1 = new Date(str1);
    var d2 = new Date(str2);

    above code line will create new Java script dates using datestring you passed so these two new dates will be in same format and you should be able to compare them...

    hope this helps..


    MayankP
    My Blog
    Follow Me on Twitter
    • Marked as answer by mimamar Thursday, January 13, 2011 10:32 AM
    Thursday, January 13, 2011 9:40 AM
    Answerer
  • Hi,

    Thanx for all your help MayankP. :) Yes I had to pass the dates as string, made few changes to the string, and succesfully solved the problem. :)

    Thursday, January 13, 2011 10:32 AM
  • you are welcome...glad to hear you resolved the problem.

     


    MayankP
    My Blog
    Follow Me on Twitter
    Thursday, January 13, 2011 11:30 AM
    Answerer