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! |
Hold your calendar on January 30, 2008 for this free webcast on the new i5/OS. Rational's Enterprise Modernization products will be discussed at this webcast as they help to drive the application development environment for this new System i OS. <br />And learn how i5/OS will take you to the next step of efficient, resilient business processing. You will hear about the new i5/OS capabilities as it will be the most significant i5/OS release in years. If you cannot join the webcast on 1/30/08 you can still use this link to listen to the replay.<br /> FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download the latest trial version of IBM Data Studio V1.1 at no cost. IBM Data Studio is a comprehensive data management solution that helps you effectively design, develop, deploy and manage your data, databases, and database applications throughout the data management life cycle utilizing a consistent and integrated user interface. Unlike other client-side data management solutions that focus on only one aspect of the application lifecycle or database administration, Data Studio complements the Rational Software Delivery platform, providing unparalleled flexibility for a heterogeneous data server environment across platforms. FREE! Go There Now!
|
|
|
|
Secure your Web applications with IBM Rational AppScan Standard Edition V7.7, previously known as Watchfire AppScan. This Web application security testing tool automates vulnerability assessments and scans and tests for common Web application vulnerabilities. Visit IBM developerWorks to download a free trial of IBM Rational AppScan Standard Edition V7.7. FREE! Go There Now!
|
|
|
|
Learn how to do more with your reusable assets with the free Rational Asset Manager eKit. The eKit includes demos on how Rational Asset Manager tracks and audits your assets in order to utilize them for reuse. Plus you’ll find white papers and a Webcast that discuss the challenges of a Service Oriented Architecture and how Rational Asset Manager can provide quick and effective solutions. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on December 4 at 1:00 pm ET to discuss how Rational Method Composer can help meet your compliance objectives. Get your questions answered! FREE! Go There Now!
|
|
|
|
Because access to government information continues to be an area of concern for many U.S. citizens with disabilities, the U.S. government enacted Section 508 of the Rehabilitation Act in 2001 to ensure that government agencies create accessible Web content, enabling all citizens to access the information they need. A fully accessible Web site makes Web content accessible to all individuals, including those with disabilities, who may be accessing Web content via a variety of user agents. Common user agents include standard Web browsers, text-only browsers, assistive devices and mobile devices such as cell phones or personal digital assistants (PDAs). FREE! Go There Now!
|
|
|
|
This whitepaper provides areas to consider when evaluating any software configuration management solution. It addresses how the IBM solutions (Rational ClearCase and Rational ClearQuest) meet the needs and requirements of both project leaders and developers to provide successful Software Change and Configuration Management. FREE! Go There Now!
|
|
|
|
Get a free trial download of the latest version of IBM Rational Functional Tester V7.0.1. Rational Functional Tester is an automated functional and regression testing solution for QA teams concerned with the quality of their Java, Microsoft Visual Studio .NET, and Web-based applications. FREE! Go There Now!
|
|
|
|
Try the latest version of IBM Rational Manual Tester V7.0.1 by downloading a free trial from IBM developerWorks. This manual test authoring and execution tool promotes test step reuse to reduce the impact of software change on testers and business analysts and addresses the needs of teams performing at least a portion of their testing manually. FREE! Go There Now!
|
|
|
|
The discipline of assembling and delivering software is maturing beyond standard developer-centric compile/test software builds. The end-to-end software development lifecycle is emerging as the new focus moves “Beyond the Build.” Join this on demand webcast to learn about methods for streamlining software delivery and key capabilities of the IBM Rational Build Forge framework for automating build and release management in environments of any size. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |