I am searching for a dynamic day of week select.
So the code would recognise today is August 1st so... would work like so.
So code ( how I would like it to perform )
<select id="selectday" name="selectday" tabindex="13">
<option value="">Please select Preferred Day</option>
<option value="">Today Wed 1st Aug</option>
<option value="">Thursday 2nd Aug</option>
<option value="">Friday 3rd Aug</option>
<option value="">Saturday 4th Aug</option>
<option value="">Sunday 5th Aug</option>
</select>
Also would like if possible to factor, if current time is => 12.00pm then Today ( becomes unavailable as an option )
Does this make sense ?
Just wondered if anyone has seen anything like this and how to do it ? Prefer jquery but I suppose php would be fine.
I see plenty of date and time pickers specifically Trents https://github.com/trentrichardson/jQuery-Timepicker-Addon
But I need something very very simple and lightweight.
Only needs to show either 7 day block or 14 day block. Would prefer if Sunday was not an option , but that isnt a major issue.
Something like this should get you started... ( Tested example )
<select id="selectday" name="selectday" tabindex="13">
<?php
$IncludeToday = date("G") < 12;
for($i=($IncludeToday?0:1);$i<=7;$i++) {
$TargetDate = strtotime(date("Y-m-d") . " +{$i} day");
print "<option value=\"" . date("Y-m-d", $TargetDate) . "\">" . date("l jS F", $TargetDate) . "</option>\n";
}
?>
</select>
This takes the current date in the format Ymd
and uses strtotime()
to parse an offset of + n days
. Then, we output an option with the proper display format and a machine-readable ymd
in the value.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.