You can use meta queries to filter posts according to your needs.
Here is a sample code:
function SearchFilter( $query ) {
if ( !is_admin() && $query->is_search ) {
$query->set( 'post_type', 'visitor' );
$query->set( 'meta_query', array(
'relation' => 'AND',
array(
'key' => 'visitor-start-date',
'value' => time(),
'compare' => '<='
),
array(
'key' => 'visitor-date',
'value' => time(),
'compare' => '>='
),
) );
}
}
add_action( 'pre_get_posts', 'SearchFilter' ); // pre_get_posts is an action, not a filter, so you don't have to return anything in it
If you want the server time, then use time
function as in code above.
On the other hand, if you need to use WP time in comparisons, then use current_time
function:
current_time( 'timestamp' );