mark107 Posted April 19, 2014 Share Posted April 19, 2014 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? Quote Link to comment https://forums.phpfreaks.com/topic/287890-changing-the-day-date-for-each-24-hours/ Share on other sites More sharing options...
QuickOldCar Posted April 20, 2014 Share Posted April 20, 2014 (edited) 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:002014-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 April 20, 2014 by QuickOldCar Quote Link to comment https://forums.phpfreaks.com/topic/287890-changing-the-day-date-for-each-24-hours/#findComment-1476719 Share on other sites More sharing options...
Strider64 Posted April 20, 2014 Share Posted April 20, 2014 Just a little side note, if you want to have the time look like a 24-hour clock the format would be: $tomorrow_date = date('Y-m-d g:i:s A', strtotime($date_and_time . ' + 1 day')); This just saves you from looking the formatting up. Quote Link to comment https://forums.phpfreaks.com/topic/287890-changing-the-day-date-for-each-24-hours/#findComment-1476741 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.