kumar217
kumar217

Reputation: 11

How do i show particular option for certain time limit

I want to show a particular time for a certain time like if time is more than 11 slot 11-2 should be hidden and the other two slots showed else to show all, then if time more than 2 pm above two slots should be hidden and only 6 pm -9 pm slot should be shown. Please suggest me the proper answer using PHP

<option value="" selected disabled>Select Delivery Time...</option>
<option value="11:00 AM to 02:00 PM">11:00 AM to 02:00 PM</option>
<option value="02:00 PM to 06:00 PM">02:00 PM to 06:00 PM</option>
<option value="06:00 PM to 09:00 PM">06:00 PM to 09:00 PM</option>

Upvotes: 1

Views: 46

Answers (1)

Andreas
Andreas

Reputation: 23968

You can use date() function.

echo '<option value="" selected disabled>Select Delivery Time...</option>';
if(date("H") < 11) echo '<option value="11:00 AM to 02:00 PM">11:00 AM to 02:00 PM</option>';
if(date("H") < 14) echo '<option value="02:00 PM to 06:00 PM">02:00 PM to 06:00 PM</option>';
if(date("H") < 18) echo '<option value="06:00 PM to 09:00 PM">06:00 PM to 09:00 PM</option>';

This assumes the server has the same timezone as your expected delivery

Upvotes: 2

Related Questions