How to compare form value in an ajax call
I found an answer for me after trying various cases. The below is the call back function which I wrote.

function check_date($form,$form_state){    
 $current_date = $form_state['values']['from_date'];
 $custom_value = sp_call_and_extract_needed_data();
 $error_message = t('your error message');
 $current_path = current_path();
 if (strpos($current_path, 'ajax') !== false) { //if call from ajax
   $commands[] = ajax_command_after('#breadcrumbs',  $error_message);
   return array('#type' =&gt; 'ajax', '#commands' =&gt; $commands);
 } else {
   form_set_error('from_date', $error_message);
 }    
}