1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

how to change the day date in the 00 hours?

Discussion in 'PHP' started by mark103, Apr 8, 2014.

  1. #1
    Hi all,

    I need your help with my PHP, I have got the date and time format especially the year, month, day date, hours, minutes and seconds. I have got a little problem with the day date.

    Most of the day date are correct, but some of them are not correct.

    Example: 20140407230000, 20140408233000, 20140408000000, 20140408003000.

    If you can take a look an the 20140408230000, you will see that 2014 is the year, 04 is the month, 08 is the day date, 23 is the hours, 00 is the minutes and seconds.

    From what I have got, the day date are wrong. I have the 08 day date when I'm on the 23 hours at the same day which is correct, but when I have the 00 hours I should have the day date 09 instead of 08.

    Here is the code:

    
    <?php
       ini_set('max_execution_time', 300);
       $errmsg_arr = array();
       $errflag = false;
       $link;
       include ('simple_html_dom.php');
       $html = file_get_html("http://www.mysite.com/get-listing.php?channels=" . $channel . "&id=" . $my_id);
    
    
       $time1 = $html_two->find('span[id=time1]',0)->plaintext; 
       $time1i = strtotime($time1);
       $title1 = $html_two->find('span[id=title1]',0)->plaintext;
    
    
       $hours = $hoursMinutes[0];
       $minutes = $hoursMinutes[1];
    
    
       $program_list[$count]['start_time1'] = date('YmdHis',$time1i);
    
    
       $xml .= "
      <channel id='" . $my_id. " " . $channel . "'>";
       $xml .= "
        <display-name>" . $my_id. " " . $channel; 
       $xml .= "</display-name>";
       $xml .= "
      <programme channel='" . $my_id. " " . $channel . "' start='" . $program_list[$i]['start_time1'] . "' stop='" . $program_list[$i]['end_time1'] . "'>";
       $xml .= "
      </programme>";
       $xml .= "
      </channels>";
      echo $xml;
    ?>
    
    Code (markup):

    Can you please tell me how I can change the day date to the next day date when I am on the 00 hours using with my code?

    Thanks in advance.
     
    mark103, Apr 8, 2014 IP
  2. BrainyBiz

    BrainyBiz Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #2
    In what format is the time displayed in the:
    <span id="time1"></span>
    HTML:
    on get-listing.php
     
    BrainyBiz, Apr 14, 2014 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #3
    I have... more questions than answers for you...

    WHY the variables for nothing? Where are $hoursMinutes and $html_two even defined? Why are you wasting time on a massive string addition when you're just going to echo out the result?!? What the devil are you doing that would return the date as BCD and why aren't you using a PROPER date type value (or say.. UTC?)

    Whatever it is you are trying to do, IMHO it looks like you are doing it ALL WRONG... though not seeing the entire picture may be part of the issue since incomplete snippets are like giving instructions for brain surgery over a time phone to 1887. You are calling values we don't see defined, there isn't enough to make any sense of your logic (if any) -- need more to really help you.

    Though I'd probably also axe that stupid "simple" dom crap and just use DOMDocument -- why waste time on some crappy external library to do what a built-in one can already do?

    Also you seem to be putting spaces in your ID's... spaces are invalid characters in ID's. It's not like classes where an element can have more than one of them. You may also want to switch to single quotes instead of doubles to make your code cleaner, a hair faster, and not have the 'wrong' quotes in your markup.

    I'm guessing WILDLY since I have no clue where 90% of your variables and values are even coming from, (or if any of them are used later where we can't see them), but I'd probably have written that more like this:

    <?php
       ini_set('max_execution_time', 300);
       $errmsg_arr = array();
       $errflag = false;
       
       $dom = new DOMDocument();
       $dom->loadHTMLFile('http://www.mysite.com/get-listing.php?channels=' . $channel . '&id=; . $my_id);
       $time1 = $dom->getElementByID('time1')->textContent;
       $title1 = $dom->getElementByID('title1')->textContent;
       $program_list[$count]['start_time1'] = date('YmdHis', strtotime($time1));
       
       echo '
      <channel id="', $my_id, '_', $channel, '">
        <display-name>', $my_id, ' ', $channel, '</display-name>
    		<programme
    			channel=", $my_id, ' ', $channel, '"
    			start="', $program_list[$i]['start_time1'], '"
    			stop="', $program_list[$i]['end_time1'], '"
    		></programme>
      </channels>';
    ?>
    Code (markup):
    Though it's likely even more of that code needs an axe swung at it.
     
    deathshadow, Apr 14, 2014 IP