how to program half hour in php H format? -


i've looking on stackoverflow , google similar question, haven't found answer fits problem. i'm still sorry if chance let duplicate question pass by. please, i'd appreaciate if kindly pointed me it.

my issue need program schedule formatted in h format in php, need add half hour , don't know how. here code can understand better mean:

$time = (int)date('h');  if($time>=24 && $time<6) {     //some code... } else if($time>=6 && $time<18) //my problem here, need 18:30 {     //some other code... } //code goes on rest of hours of day 

i tried changing $time (int)date('h:i'), when write if($time>=6:00 && $time<18:00) error because of ':'

edit: ok tried both ways, here's code looks like

    date_default_timezone_set('america/lima');     if (!isset($timestamp)) {         $timestamp = time();     }     $dw = date( "w", @$timestamp);     $time = date('hh:ii');      if($dw>0 && $dw<=4)     {          if($time>="00:00" && $time<"04:00")         {             $show->current = "a";             $show->next= "b";         }     else if($time>="04:00" && $time<"06:30")     {     $show->current = "b";             $show->next= "c";        }         else if($time>="06:30" && $time<"09:00")         {             $show->current = "c";             $show->next= "d";         } 

and keeps going until reaches 00:00 again. problem way doesn't seem recognize @ date, if example edit current c time start @ 06:00 instead of 06:30, doesn't update on site.

    date_default_timezone_set('america/lima');     if (!isset($timestamp)) {         $timestamp = time();     }     $dw = date( "w", @$timestamp);     $time = date('g');       if($dw>0 && $dw<=4)        {          if($time>=0 && $time<4)         {             $show->current = "a";             $show->next= "b";         }     else if($time>=4 && $time<6.5)     {     $show->current = "b";             $show->next= "c";        }         else if($time>=6.5 && $time<9)         {             $show->current = "c";             $show->next= "d";         } 

here updates fine, doesn't recognize 6.5 6:30, @ time instead of getting current c show, continue getting b.

you casting $time integer, that's why doesn't work.
try:

$time = date('h:i');     // <-- without "(int)" part  if (($time >= "00:00") && ($time < "06:00")) {     //some code... } else if (($time >= "06:00") && ($time < "18:30") {     //some other code... } else {     //code goes on rest of hours of day } 

edit:
make sure prefix hours between 0 , 9 zero, e.g. use 06:... instead of 6:....
(thx marc b heads-up).

edit2: according docs regarding format characters h , i:

#    format # character   description                                    returned values  #         h   24-hour format of hour leading zeros   00 through 23 #           minutes leading zeros                     00 59 

so, expect values 00:00 23:59 in $time (not example 24:00).


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -