-1

i have this code and i need a good condition to stop people booking for one day

$output['date_pickup'] = $pickup;
$output['date_return'] = $return;

// strtotime
$pickup_dtime = strtotime( $output['date_pickup'] . $output['time_pickup'] );
$return_dtime = strtotime( $output['date_return'] . $output['time_return'] );

// PAST TIME?
if ( date('Y-m-d') == $output['date_pickup'] && date_i18n('H:i') > $output['time_pickup'] )
    $error .= sprintf(__('Today, you cannot book before %s.', 'textZ'), date_i18n('H:i')) . '<br />';

i try this code but i can't reserve any way the date of retrn is bigger than 24H

if ( $return < 86400 )
    $error .= __('today you cannot book.', 'textZ') . '<br />';

So can you help please

1 Answers1

-1

the following fiddle shows you how you can easily accomplish this using the timestring provided by the javascript Date object:
http://jsfiddle.net/jlss/au4tLncg/

basically:

var now = new Date(pickup).getTime();
var target = new Date(return).getTime();

if (now+(24*60*60*1000) <= target) {
    return true;
}
return false;

note that in newer browsers (not IE8-) you can also use .now() instead of .getTime() (source: How do you get a timestamp in JavaScript?)

Note: it seems your code example is PHP though, and not javascript/jquery

in php you can use strtotime() instead of the Date objects, reference: http://be2.php.net/function.strtotime general example:

if (($timestamp = strtotime($str)) === false) {
    echo "The string ($str) is bogus";
} else {
    echo "$str == " . date('l dS \o\f F Y h:i:s A', $timestamp);
}
Community
  • 1
  • 1
Jonas D.
  • 361
  • 4
  • 18