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 8 of 8
  1. #1
    Regular Coder
    Join Date
    Sep 2008
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts

    how to change the day date in 00 hours?

    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:

    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;
    ?>

    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.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    I take it that you're trying to parse this HTML (the result of your "get-listing"):
    Code:
    <span id="time1">3:00 PM </span> - <span id=title1>Boy Meets WorldThe Father/Son GameTV-G </span>
    <span id="time2">3:30 PM </span> - <span id=title2>Boy Meets WorldOnce in Love With AmyTV-G </span>
    <span id="time3">4:00 PM </span> - <span id=title3>Boy Meets WorldShe Loves Me, She Loves Me NotTV-G </span>
    <span id="time4">4:30 PM </span> - <span id="title4">Boy Meets World"The B-Team of Life"TV-G </span>
    <span id="time5">5:00 PM </span> - <span id=title5>The MiddleChristmas  </span>
    <span id="time6">5:30 PM </span> - <span id=title6>The MiddleSiblings  </span>
    <span id="time7">8:00 PM </span> - <span id="title7">Alice in WonderlandTV-PG &nbsp;(V)</span>
    <span id="time8">11:00 PM </span> - <span id="title8">Harry Potter and the Prisoner of AzkabanTV-PG  &nbsp;(L,V)</span>
    <span id="time9">12:00 AM </span> - <span id="title9">The 700 ClubTV-G  </span>
    Is "get-listing.php" your own script?

    Are you creating that HTML as shown above using "get-listing.php"?

    You can't just throw something like this into "strtotime" ... 12:00 AM

    If all you give it is a time and assume your TV listing is for 'today', then you'll get 'today'. It does not know that 12:00 AM is supposed to be 'tomorrow', or as you call it, the next day. you have to give "strtotime" more information to get an accurate result.

    I guess I'm asking ... where are you getting these listings from?
    I have a hunch these listings are coming from an API, or RSS Feed?

  • #3
    Regular Coder
    Join Date
    Sep 2008
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Basically what you said, yes the get-listing.php is my own script. I wrote it all myself to fetch the data I want. And yes I am creating that HTML as shown from what you have post.

    I know that I can't throw something into "strtotime", but I was advised to changed it as i had the hours wrong when I used the code like this when I had 12am which it show as 12 (supposed to be 00):

    Code:
       $time1 = $html_two->find('span[id=time1]',0)->plaintext;
    		
       $time1 = explode(" ", $time1);
       $hoursMinutes = explode(":", $time1[0]);
       $hours = $hoursMinutes[0];
       $minutes = $hoursMinutes[1];
    		
       if($time1[1] == "PM")
       {
          $time1[0] = date("Ymd") . ((int)($hours) + 12) . $minutes . "00";
       } 
       else 
       {
          $time1[0] = date("Ymd") . $hours . $minutes . "00";
       }
       $program_list[$count]['start_time1'] = $time1[0];
    
       $time2 = $html_two->find('span[id=time2]',0)->plaintext;
      
      //$time2 = $html_two->find('span[id=time2]',0)->plaintext; 
      //$time2i = strtotime($time2); 
      $title2 = $html_two->find('span[id=title2]',0)->plaintext;
      
      $time2 = explode(" ", $time2);
      $hoursMinutes = explode(":", $time2[0]);
      $hours = $hoursMinutes[0];
      $minutes = $hoursMinutes[1];
    		
      if($time2[1] == "PM")
      {
        $time2[0] = date("Ymd") . ((int)($hours) + 12) . $minutes . "00";
      } 
      else 
      {
        $time2[0] = date("Ymd") . $hours . $minutes . "00";
      }
      $program_list[$count]['end_time1'] = $time2[0];
      $program_list[$count]['start_time2'] = $time2[0];
    
      $time3 = $html_two->find('span[id=time3]',0)->plaintext;
      
      //$time3 = $html_two->find('span[id=time3]',0)->plaintext; 
      //$time3i = strtotime($time3); 
      $title3 = $html_two->find('span[id=title3]',0)->plaintext;
      
      $time3 = explode(" ", $time3);
      $hoursMinutes = explode(":", $time3[0]);
      $hours = $hoursMinutes[0];
      $minutes = $hoursMinutes[1];
    		
      if($time3[1] == "PM")
      {
        $time3[0] = date("Ymd") . ((int)($hours) + 12) . $minutes . "00";
      } 
      else 
      {
        $time3[0] = date("Ymd") . $hours . $minutes . "00";
      }
      $program_list[$count]['end_time2'] = $time3[0];
      $program_list[$count]['start_time3'] = $time3[0];
    
    
      $time4 = $html_two->find('span[id=time4]',0)->plaintext;
      
      //$time4 = $html_two->find('span[id=time4]',0)->plaintext; 
      //$time4i = strtotime($time4); 
      $title4 = $html_two->find('span[id=title4]',0)->plaintext;
      
      $time4 = explode(" ", $time4);
      $hoursMinutes = explode(":", $time4[0]);
      $hours = $hoursMinutes[0];
      $minutes = $hoursMinutes[1];
    		
      if($time4[1] == "PM")
      {
        $time4[0] = date("Ymd") . ((int)($hours) + 12) . $minutes . "00";
      } 
      else 
      {
        $time4[0] = date("Ymd") . $hours . $minutes . "00";
      }
      $program_list[$count]['end_time3'] = $time4[0];
      $program_list[$count]['start_time4'] = $time4[0];

    I can see that I still get the day date and hours time are wrong.

    Here is the XML output where you will see it:

    Code:
    <channel id="101 ABC FAMILY">
    <display-name>101 ABC FAMILY</display-name>
    <programme channel="101 ABC FAMILY" start="20140408170000" stop="20140408173000">
    <title lang="en"></title>
    <sub-title lang="en"></sub-title>
    <desc lang="en"></desc>
    <category lang="en"></category>
    </programme>
    <programme channel="101 ABC FAMILY" start="20140408173000" stop="20140408180000">
    <title lang="en"></title>
    <sub-title lang="en"></sub-title>
    <desc lang="en"></desc>
    <category lang="en"></category>
    </programme>
    <programme channel="101 ABC FAMILY" start="20140408180000" stop="20140408200000">
    <title lang="en"></title>
    <sub-title lang="en"></sub-title>
    <desc lang="en"></desc>
    <category lang="en"></category>
    </programme>
    <programme channel="101 ABC FAMILY" start="20140408200000" stop="20140408230000">
    <title lang="en"></title>
    <sub-title lang="en"></sub-title>
    <desc lang="en"></desc>
    <category lang="en"></category>
    </programme>
    <programme channel="101 ABC FAMILY" start="20140408230000" stop="20140408120000">
    <title lang="en"></title>
    <sub-title lang="en"></sub-title>
    <desc lang="en"></desc>
    <category lang="en"></category>
    </programme>
    <programme channel="101 ABC FAMILY" start="20140408120000" stop="20140408123000">
    <title lang="en"></title>
    <sub-title lang="en"></sub-title>
    <desc lang="en"></desc>
    <category lang="en"></category>
    </programme>
    <programme channel="101 ABC FAMILY" start="20140408123000" stop="2014040810000">
    <title lang="en"></title>
    <sub-title lang="en"></sub-title>
    <desc lang="en"></desc>
    <category lang="en"></category>
    </programme>
    <programme channel="101 ABC FAMILY" start="2014040810000" stop="2014040813000">
    <title lang="en"></title>
    <sub-title lang="en"></sub-title>
    <desc lang="en"></desc>
    <category lang="en"></category>
    </programme>
    <programme channel="101 ABC FAMILY" start="2014040813000" stop="">
    <title lang="en"></title>
    <sub-title lang="en"></sub-title>
    <desc lang="en"></desc>
    <category lang="en"></category>
    </programme>
    </channel>

    Do you know how I can change the 12 hours into 24 hours and how I can change the day date depends on the current day date?

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    I think you need to post "get-listing.php".

    I have a hunch that you're doing more work than you need to do.

    If this:
    <span id="time11">12:00 AM </span> - <span id="title11">My TV Show </span>

    .. is the only information you have to create 201404080000, then you're screwed.
    There is nothing you can do to determine the day number.

    You tell me from looking at the <span> line what day I'm trying to show.
    Last edited by mlseim; 04-08-2014 at 11:36 PM.

  • #5
    Regular Coder
    Join Date
    Sep 2008
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts
    do you mean the output?

    if so, here it is:


    Code:
    <span id="time1">8:00 PM </span> - <span id="title1">Harry Potter and the Prisoner of Azkaban</span><br><br><span id="time2">11:00 PM </span> - <span id="title2">The 700 Club</span><br><br><span id="time3">12:00 AM </span> - <span id="title3">The Fresh Prince of Bel-Air: Winner Takes Off</span><br><br><span id="time4">12:30 AM </span> - <span id="title4">The Fresh Prince of Bel-Air: Robbing the Banks</span><br><br><span id="time5">1:00 AM </span> - <span id="title5">The Fresh Prince of Bel-Air: Bundle of Joy</span><br><br><span id="time6">1:30 AM </span> - <span id="title6">The Fresh Prince of Bel-Air: Best Laid Plans</span><br><br><span id="time7">2:00 AM </span> - <span id="title7">Shaun T's Focus T25</span><br><br><span id="time8">2:30 AM </span> - <span id="title8">I Hate My Hair!</span><br><br><span id="time9">3:00 AM </span> - <span id="title9">The 700 Club</span><br><br>

    As you said that I'm screwed if i have the only information. Dude!!! I didn't code it most of it, but it was the PHP developer who coded it for me. I have the proof if you don't believe it, the link is: http://pastebin.com/a0wQsnch

    I found out that he had done a dodgy work, many of the code I found are unnecessary. I have to recode it myself by finding the list of code that I actually needs and what code I do not need it. So my code is working much better than his which I have list for every channels where he doesn't have the list for every channels. There are something in my code that need a little bit of modify to make the changes that's all.

    The main thing is he has got the day date change with a 24 hours clock, e.g.: 20140408230000, 20140409000000, 20140409010000, 20140409230000, 20140410000000 and so on. I can't figure it out where it is. I hope you will be able to help me where to find it.

    Apart from this, I'm fetching the time data from my get-listing.php script where I fetch the data from the TV guide website. I'm splitting the time into the hours and minutes. So I need to convert the hours into 24 hours and I also need to change the day date. If you can help me how I can convert the hours into 24 hours when I'm fetching the time data and also to change the day date depends on what day it have in the variable, e.g.: if the time in the $time1 variable have the 23 hours and the day date is 09, then in the $time2 variable it will have the 00 hours and the day date would be 10. I would be very grateful if you could help me out.

  • #6
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    To answer your original question, I think the snippet of code below will work (untested).

    In my snippet, I only picked "time4" to show you the change. My logic is this: If the time is PM, nothing changes. If the time is AM, it looks to see if the hour happens to be '12'. If it's 12, then it must be tomorrow, not today ... so it adds a day.

    Code:
    $time4 = explode(" ", $time4);
      $hoursMinutes = explode(":", $time4[0]);
      $hours = $hoursMinutes[0];
      $minutes = $hoursMinutes[1];
    		
      if($time4[1] == "PM")
      {
        $time4[0] = date("Ymd") . ((int)($hours) + 12) . $minutes . "00";
      } 
      else 
      {
    	if($hours=="12"){
        $time4[0] = date('Ymd', strtotime(' +1 day')) . $hours . $minutes . "00";
    	}
    	else{
    	$time4[0] = date("Ymd") . $hours . $minutes . "00";
    	}
      }
    If that fixes it let me know.

    Meanwhile, if you can post the entire script called 'get-listing.php'. And by that, I mean the script that originally goes to the TV Guide and gets the times for each channel.


    .
    Last edited by mlseim; 04-09-2014 at 06:46 PM.

  • #7
    Regular Coder
    Join Date
    Sep 2008
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you very much for this, I can see the code you have post is working right now. The day date have change when I have the 12 AM.

    Will I be able to add the day date in a later time, e.g the first 12 am I add the day date to the next day from 08 to 09 and then later on I have another time 12 am to change from 09 to 10 and so on?

    Can you please also help me how I can convert the 12 hours into 24 hours?

    The strings that I need to change the 12 hours into 24 hours, these are only in AM:

    Code:
    12
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11

  • #8
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Use the same snippet in each time section, time1, time2, etc. because you don't know for sure which time section has 12AM (midnight).

    I don't understand your 24 hour question.

    AM times are already in 24 format. It's the PM times that go from 12 to 23

    Your day should be like this:

    00
    01
    02
    03
    04
    05
    06
    07
    08
    09
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23


    Also, give me the URL you are using for TV Guide ... is that the script you put into 'pastebin'? I'll have to look at that later because I can't access 'pastebin' from behind the firewall I'm on now.
    Last edited by mlseim; 04-10-2014 at 01:54 PM.


  •  

    Posting Permissions

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