Date Time Code

  Home arrow Date Time Code arrow Generate Time Option List for Select s...
DATE TIME CODE

Generate Time Option List for Select statement
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 6
    2005-08-07

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    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

    blog comments powered by Disqus

    DATE TIME CODE ARTICLES

    - DaysInSpan.php
    - MySQLdateSpan.php
    - DateSpan.php
    - FutureDateFormEntry.php
    - Generate Time Option List for Select stateme...
    - Current Age Script (v2)
    - class for some mysql imitated time functions
    - Current Age Script, up to the last day
    - filemtime_remote
    - Page Generation Time Figure-Outer
    - convGMT v2
    - Benchmarker
    - Simple PHP Calendar
    - Display message according to hour of day
    - Display Date Function

    Developer Shed Affiliates

     



    © 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap