Time Range Array in PHP
Submitted by alpha_luna on Monday, September 12, 2016 - 09:52.
In this tutorial, we are going to create Time Range Array in PHP. If you are going to create a time picker using dropdown elements to select time, then there are many ways to do that. The user can use jQuery plugins to create a simple time picker and much better to use custom time range in the drop-down to select time. We are going to use PHP and jQuery plugin so we can easily create a time range array in the dropdown to have a time picker.
We are going to set the start and end time in the dropdown time picker.
Required
Using this simple HTML source code and PHP source code above will generate a simple dropdown time picker using the time range array. Copy and paste this simple HTML source code to the BODY tag of your web page.
For the full source code, kindly click the "Download Code" button below.
- start - 7:30am or 7:30
- end - 8:30pm or 20:30
- time interval - 1 hour, 1 mins, or 1 secs, etc
- time format - 12 or 24
- <?php
- function create_time_range($start, $end, $interval = '30 mins', $format = '12') {
- $time_Format = ($format == '12')?'g:i:s A':'G:i:s';
- $difference_time = $time_adding - $current_time;
- while ($time_to_Start < $time_to_End) {
- $time_to_Start += $difference_time;
- }
- return $time_lists;
- }
- $time_lists = create_time_range('7:30', '23:30', '30 mins');
- ?>
Output
