I have a site that uses several start and end times and also various other times that have to be scheduled. I needed to be able to narrow down the listing with start and end times. I also wanted to be able to specify various time increments in minutes. My last requirement was that I needed to be able to show what time was stored in the database by specifying the SELECTED attribute for the option statement.
This is something I am posting to give back to this site as I have used it over and over to help me in a large project I am finalizing in the next week or so.
By : fbnewtz
function create_time_dropdown($start,$stop,$mininc,$hoursel,$minsel)
{
for ($hour = $start; $hour <= $stop; $hour++)
{
if ($hour == '0')
{
$disphour = '12';
$ampm = 'AM';
} else if ($hour >= '13' && $hour <= '21')
{
$test = $hour - 12;
$disphour = '0' . $test;
$ampm = 'PM';
} else if ($hour >= '22' && $hour <= '23')
{
$disphour = $hour - 12;
$ampm = 'PM';
} else {
$disphour = $hour;
$ampm = 'AM';
}
for ($min = 0; $min <= 59; $min += $mininc)
{
if ($hour >= '1' && $hour <= '9')
{
if($min >= '0' && $min <= '9')
{
if ($hour == $hoursel && $min == $minsel)
{
echo '<option value="0' . $hour . ':0' . $min . ':00" selected>0' . $disphour . ':0' . $min . ' ' . $ampm . '</option>';
} else {
echo '<option value="0' . $hour . ':0' . $min . ':00">0' . $disphour . ':0' . $min . ' ' . $ampm . '</option>';
}
} else {
if ($hour == $hoursel && $min == $minsel)
{
echo '<option value="0' . $hour . ":" . $min . ':00" selected>0' . $disphour . ':' . $min . ' ' . $ampm . '</option>';
} else {
echo '<option value="0' . $hour . ":" . $min . ':00">0' . $disphour . ':' . $min . ' ' . $ampm . '</option>';
}
}
} else {
if ($min >= '0' && $min <= '9')
{
if ($hour == $hoursel && $min == $minsel)
{
echo '<option value="' . $hour . ':0' . $min . ':00" selected>' . $disphour . ':0' . $min . ' ' . $ampm . '</option>';
} else {
echo '<option value="' . $hour . ':0' . $min . ':00">' . $disphour . ':0' . $min . ' ' . $ampm . '</option>';
}
} else {
if ($hour == $hoursel && $min == $minsel)
{
echo '<option value="' . $hour . ":" . $min . ':00" selected>' . $disphour . ':' . $min . ' ' . $ampm . '</option>';
} else {
echo '<option value="' . $hour . ":" . $min . ':00">' . $disphour . ':' . $min . ' ' . $ampm . '</option>';
}
}
}
}
}
}
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Date Time Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
Visit IBM developerWorks to download a free trial version of Lotus Quickr 8.0, which enables collaboration by transforming the way everyday business content such as documents, rich media, photos, and video can be shared. Lotus Quickr makes it faster and easier to share content of all types (not just documents) within virtual teams. It is designed to make it easier to collaborate across organizational boundaries, while continuing to work within the context of familiar desktop applications. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of WebSphere Business Modeler Advanced V6.1.1, IBM’s premier business process modeling and analysis tool for business users that offers process modeling, simulation, and analysis capabilities. IBM WebSphere Business Modeler helps you visualize, understand, and document business processes for continuous improvement. FREE! Go There Now!
|
|
|
|
In this tutorial, you can learn how to install and configure the IBM Rational Asset Manager Eclipse client, explore the different views in the Asset Management perspective, learn various search techniques, work with existing assets, and submit a new asset. FREE! Go There Now!
|
|
|
|
Manage, govern, and share services across your organization by using WebSphere Service Registry and Repository. Follow the hands-on exercises to learn how to navigate the Web interface to publish, find, reuse, and update services. FREE! Go There Now!
|
|
|
|
Analysts, architects, and developers who have existing COBOL or PL/I skills and want to extend those skills to deploy new workloads on the mainframe can use the IBM Enterprise Modernization Sandbox for System z to find hands-on walkthroughs of common real world scenarios. The scenarios provide examples of how to rapidly design, create, assemble, test, and deploy high-quality Web, Web services, portal, and SOA applications for IBM CICS, IBM IMS, and IBM WebSphere Application Server. FREE! Go There Now!
|
|
|
|
Ken Krugler, co-founder of code search company Krugle, and Laura Merling, vice president of Marketing and Business Development for Krugle, join to talk about the ins and outs of code search and what it means as a new feature for developerWorks users. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on December 11 at 1:00 pm ET to get tips on building your own plugins with Rational Method Composer. Get your questions answered! FREE! Go There Now!
|
|
|
|
As organizations have grown increasingly dependent on online software, the risk of malicious attacks has also become far more serious. Fortunately, well-governed organizations can protect their Web applications by injecting vulnerability assessments and ethical hacks into their software development and delivery processes. This paper describes 12 of the most common hacker attacks and provides basic rules that you can follow to help create more hack-resistant Web applications. FREE! Go There Now!
|
|
|
|
Get a free trial download of the latest version of IBM Rational Method Composer V7.2 which helps you deliver customized yet consistent process guidance to your project teams and IT organization, and includes the latest version of IBM Rational Unified Process (RUP), which has provided process guidance to teams since 1996. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference, to hear how Enterprise Generation Language (EGL) eliminates the need for tedious and error-prone low level coding, so developers can focus on business requirements. EGL extends the Rational software development platform with a simplified programming language that enables developers who have little or no experience with Java, Web technologies or Service Oriented Architecture, to create enterprise-class applications and services quickly and easily. It also allows developers who may have little or no mainframe programming experience to quickly create traditional mainframe components. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |