Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Sep 2010
    Posts
    122
    Thanks
    6
    Thanked 0 Times in 0 Posts

    how find time between two times??

    hi i have problem that getting time between two given times

    if $b2=18:02:15

    want to check weather this is between 17:30:00 and 18:30:00

    how do i check $b2 is between 17:30:00 and 18:30:00

    plz solve this problem

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Use datetime since it is overloaded to work with comparison operators.
    PHP Code:

    $b2 
    = new DateTime('18:02:15');
    $lb = new DateTime('17:00:00');
    $ub = new DateTime('18:30:00');

    iif ($b2 >= $lb && $b2 <= $ub)
    {
        
    printf('%s is between %s and %s' PHP_EOL,
            
    $b2->format('H:i:s'), $lb->format('H:i:s'), $ub->format('H:i:s'));

    So long as you don't have to concern yourself with a mix between Dates and Times (but either full date and time or just time will work), than that should work fine.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    And expand on what you are doing to check the weather. There are ways to use weatherunderground, yahoo weather or some other online service to get current weather statistics. You could also use a CRON job to grab stats every five minutes or so and create a small database of an hour's worth of data.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •