mark107 Posted April 8, 2014 Share Posted April 8, 2014 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; ?> 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. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted April 8, 2014 Share Posted April 8, 2014 Are you sure that is correct? What is the original date/time? $time1 Your are converting the original date/time to a timestamp ($time1i = strtotime($time1)) and then using date() to format it into a hard to read date format of YYYYMMDDHHMMSS. Also are you sure you're using the same timezone as the original date/time? This could have an affect on the outcome of the date. Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 8, 2014 Share Posted April 8, 2014 Impossible to really help you without knowing what the input values look like. Quote Link to comment Share on other sites More sharing options...
mark107 Posted April 8, 2014 Author Share Posted April 8, 2014 Yes, it is. The original time 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 Yes, 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. However, I tried this: //time1 $time1 = $html_two->find('span[id=time1]',0)->plaintext; $title1 = $html_two->find('span[id=title1]',0)->plaintext; $hoursMinutes = explode(":", $time1[0]); $hours = $hoursMinutes[0]; $minutes = $hoursMinutes[1]; $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]; It wont let me to change the day date and also it won't let me to have the 24 hours clock, only 12 hours. Can you please tell me what change I need to make in order i can make the 24 hours clock and change the day date depends on the current day? Are you sure that is correct? What is the original date/time? $time1 Your are converting the original date/time to a timestamp ($time1i = strtotime($time1)) and then using date() to format it into a hard to read date format of YYYYMMDDHHMMSS. Also are you sure you're using the same timezone as the original date/time? This could have an affect on the outcome of the date. Quote Link to comment Share on other sites More sharing options...
mark107 Posted April 9, 2014 Author Share Posted April 9, 2014 does anyone know?? Quote Link to comment Share on other sites More sharing options...
davidannis Posted April 9, 2014 Share Posted April 9, 2014 If what you want is the date to role over at midnight I think you mean: if($time1[1] == "PM") { if ($hours==12){ $date = date_create();//default is now I think date_modify($date, '+1 day'); // adds 1 day if it is midnight $time1[0] = date_format($date, 'Y-m-d') . ((int)($hours) + 12) . $minutes . "00"; }else{ $time1[0] = date("Ymd") . ((int)($hours) + 12) . $minutes . "00"; } not sure why it wouldn't roll over on its own. Quote Link to comment 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.