You can rename file on upload context through validator functions
here is the edited code
<code>
$form['image_fid'] = array(
'#title' => t('Image'),
'#type' => 'managed_file',
'#upload_location' => 'public://',
'#upload_validators'=> array('file_validate_name' => array()),
);
</code>
<code>
function file_validate_name(stdClass $file)
{
$errors = array();
//generate file name
$new_filename = convert_filename_to_filename_date($file->filename);
$file->filename = $new_filename;
//changing file location
$destination_dir = "public://file_location/";
//check if file exists. if exists rename it append incremental number until the filename is unique
$file->destination = file_destination($destination_dir.$file->filename, FILE_EXISTS_RENAME);
// If file_destination() returns FALSE then $replace == FILE_EXISTS_ERROR and
// there's an existing file so we need to bail.
if ($file->destination === FALSE)
{
$errors[] = t('The file %source could not be uploaded because a file by that name already exists in the destination %directory.',
array('%source' => $file->source, '%directory' => $destination_dir));
}
return $errors;
}
</code>