Jump to content

Changing the day date for each 24 hours


mark107

Recommended Posts

I'm writing a PHP to generating the time and date to output them in the XML. I have got a problem with the day date. 

 

For each 24 hours, I have the day date adding to the next day date, e.g. I have the 24 hours time 00, 01 with same following day date 19th of april, the next 24 hours the hours is 00, 01 with next following day date 20th of april and so on. On my XML output, you can see that some day date have been used in the wrong date for each hours.

 

Here is for example what it supposed to be:

 



    <tv generator-info-name="www.site.com/XMLTV">
    <channel id="101 ABC FAMILY">
    <display-name>101 ABC FAMILY</display-name>
    <programme channel="101 ABC FAMILY" start="20140419143000" stop="20140419163000">
    <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="20140419163000" stop="20140419181500">
    <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="20140420080000" stop="20140420100000">
    <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="20140420100000" stop="20140419120000">
    <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="20140420120000" stop="20140420143000">
    <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="20140420143000" stop="20140420161200">
    <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="20140420161200" stop="20140420175700">
    <title lang="en"></title>
    <sub-title lang="en"></sub-title>
    <desc lang="en"></desc>
    <category lang="en"></category>
    </programme>


 

 

 

 

As you can see in the XML output, 2014 is the year, 04 is the month and 19 and 20 is the day date of the month. You can see that i have some day date are wrong for each 24 hours. 

 

 

Here is my XML:

 



    <tv generator-info-name="www.site.com/XMLTV">
    <channel id="101 ABC FAMILY">
    <display-name>101 ABC FAMILY</display-name>
    <programme channel="101 ABC FAMILY" start="20140419143000" stop="20140419163000">
    <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="20140419163000" stop="20140419181500">
    <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="20140420080000" stop="20140420100000">
    <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="20140420100000" stop="20140419120000">
    <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="20140419120000" stop="20140419143000">
    <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="20140419143000" stop="20140420161200">
    <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="20140420161200" stop="20140420175700">
    <title lang="en"></title>
    <sub-title lang="en"></sub-title>
    <desc lang="en"></desc>
    <category lang="en"></category>
    </programme>


 

 

 

I have attached for you to take a look at my code: http://pastebin.com/CxX08Etp

 

I have spent some days to try to find the solution when I write the list of code to allow me to add the day date to the next day for each 24 hours, e.g: in one day i have the date 19 of april and the hours is 00, 01, 02 with the same following day date, the next day date is 20 of april and the hours is 00, 01, 02 with the same following day date and so on. 

 

Some hours I have got in the XML it will show the previous day date which it supposed to be show the next day date. I'm using simple_html_dom to allow me to parsing the list of strings from get-listing.php. 

 

 

Here is the list of time strings:

 



    10:00 AM
    
    12:30 PM
    
    2:30 PM
    
    4:30 PM


    6:15 PM
    
    8:00 PM
    
    10:03 PM
    
    12:30 AM
    
    1:00 AM
    
    5:30 AM
    
    6:00 AM
    
    7:30 AM
    
    8:00 AM
    
    10:00 AM
    
    12:00 PM
    
    2:30 PM
    
    4:12 PM
    
    5:57 PM
    
    8:00 PM
    
    10:00 PM
    
    12:00 AM
    
    12:30 AM


 

 

I have been so frustrated and I can't be able to find out how to add the day date for each 24 hours. Does anyone know how I can add the day date to the next day date for each 24 hours?

Link to comment
Share on other sites

That's some crazy time stuff you have going on there, here is an example of a function to use normal date and timestamp functions?

Then it's simple to add 24 hours or whatever need to do.

 

returns:

2014-04-20 12:00:00
2014-04-21 12:00:00

<?php
$date_string = "20140420120000";
 
function jumbledDate($date_string){
return $date_string[0].$date_string[1].$date_string[2].$date_string[3]."-".$date_string[4].$date_string[5]."-".$date_string[6].$date_string[7]." ". $date_string[8].$date_string[9].":".$date_string[10].$date_string[11].":".$date_string[12].$date_string[13];
}
 
$date_and_time = jumbledDate($date_string);
echo $date_and_time."<br />";
 
$tomorrow_date = date('Y-m-d H:i:s', strtotime($date_and_time . ' + 1 day'));
echo $tomorrow_date."<br />";
?>
Edited by QuickOldCar
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.