Jump to content

problem with times


black_box

Recommended Posts

I have a radio program application and

 

I have two text field

ONE IS FOR DESCRIPTION

ANOTHER IS FOR time

 

User will give description and time for present day and it goes to database

 

Example: Current time: 9:47

 

Past song: sakira: whenever              9:40

Present song: artist: title      On air    9:45

Next Song: James: Bond                  10:00

 

System will take the current time and show on air message for song that is between a range. If the time change then the On air sign will be change and goes to that song which is belogs to current time range.

 

ON AIR WILL BE CHANGE BASED ON SYSTEM TIME

 

Any solution???

Link to comment
https://forums.phpfreaks.com/topic/94411-problem-with-times/
Share on other sites

bt thts not my answer

 

The program will take my system time and compare with user inputs and then if the user input range is within system time like: 9:45 to 10:00 it will show on air for that song if system time is 10:00 then it will change to another song which time is 10:00

Link to comment
https://forums.phpfreaks.com/topic/94411-problem-with-times/#findComment-483550
Share on other sites

Ok again i m clearing that:

 

I will insert some song info in the page those data will go to database.

 

An clear example: (but it depends on user input and system time so its dynamic)

 

9:40

 

9:45 On air

 

10:00

 

The system time is : 9:47

 

Program will take the system time and search for this time if not found then it will check for the range and the range is 9:45 to 10:00 so it will make 9:45 on air.

 

Got it ?

Link to comment
https://forums.phpfreaks.com/topic/94411-problem-with-times/#findComment-483557
Share on other sites

nevermiind i think this is what you are looking for :

 

 

<?php

/**
* create_time_range 
* 
* @param mixed $start start time, e.g., 9:30am or 9:30
* @param mixed $end   end time, e.g., 5:30pm or 17:30
* @param string $by   1 hour, 1 mins, 1 secs, etc.
* @access public
* @return void
*/
function create_time_range($start, $end, $by='30 mins') {

    $start_time = strtotime($start);
    $end_time   = strtotime($end);

    $current    = time();
    $add_time   = strtotime('+'.$by, $current);
    $diff       = $add_time-$current;

    $times = array();
    while ($start_time < $end_time) {
        $times[] = $start_time;
        $start_time += $diff;
    }
    $times[] = $start_time;
    return $times;
}

// create array of time ranges
$times = create_time_range('9:30', '17:30', '30 mins');

// more examples
// $times = create_time_range('9:30am', '5:30pm', '30 mins');
// $times = create_time_range('9:30am', '5:30pm', '1 mins');
// $times = create_time_range('9:30am', '5:30pm', '30 secs');
// and so on

// format the unix timestamps
foreach ($times as $key => $time) {
    $times[$key] = date('g:i:s', $time);
}


print '<pre>'. print_r($times, true).'</pre>';
/*
* result
*
Array
(
    [0] => 9:30:00
    [1] => 10:00:00
    [2] => 10:30:00
    [3] => 11:00:00
    [4] => 11:30:00
    [5] => 12:00:00
    [6] => 12:30:00
    [7] => 1:00:00
    [8] => 1:30:00
    [9] => 2:00:00
    [10] => 2:30:00
    [11] => 3:00:00
    [12] => 3:30:00
    [13] => 4:00:00
    [14] => 4:30:00
    [15] => 5:00:00
    [16] => 5:30:00
)

*/

?> 

Link to comment
https://forums.phpfreaks.com/topic/94411-problem-with-times/#findComment-483615
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.