Jump to content

How to change the day date?


mark107

Recommended Posts

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.
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.