Hi all,

I need your help with my PHP, I'm working on 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: 20140408230000, 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 24 hours I should have the day date 09 instead of 08.

The original string for the $time1 is:

6:00 PM 
6:00 PM 
7:00 PM 
6:00 PM 
7:00 PM 
7:00 PM 
7:00 PM 
7:00 PM 
7:00 PM 
7:00 PM 
7:00 PM 
7:00 PM 
7:00 PM 
7:00 PM 
7:00 PM 
7:00 PM

I'm converting the original time to a timestamp, because I want to get the 24 hours time, but the day date won't change. The 24 hours is working when I use the code like this:

   $time1 = $html_two->find('span[id=time1]',0)->plaintext; 
   $time1i = strtotime($time1);

   $hours = $hoursMinutes[0];
   $minutes = $hoursMinutes[1];

   $program_list[$count]['start_time1'] = date('YmdHis',$time1i);

Here is the output from get-listing.php:

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

Here is the PHP:

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

It wont let me to change the day date when I'm using my current code. I'm aware and I knew that most of the code are unnecessary, but it wasn't from me who coded it. It was the PHP developer that I hired 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.

Can you please tell me what change I need to make in order i can change the day date with a 24 hours clock depends on the current day?

Thanks in advance.

Member Avatar for diafol

2400 is not a valid time -it's 0000

@diafol do you know how i can check on the hours if i have 12am before i can change it to 0000? And also how i can change the day date depends on the current day?

e.g: I have the $time1 variable that I have 23 hours and the day date is 08, in the $time2 variable I have the 12 hours (show as 12am) and i check the day date in the $time1 variable then i can add the day date in the $time2 variable to the next day date.

How I can do that?

Member Avatar for diafol

Sorry I don't understand. Could you show an example of what you mean?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.