Jump to content

Recommended Posts

I need some help with set up the date format.
 
I'm still trying to find out how I can set up the format to the next day, the day two and the day three date when I work out with the hours.
 
Example: I set up the date format from today and the time is 10:00 AM, 11:00 AM, 12:00 PM, the format is 20140424100000, 20140424110000, 20140424120000 and so on until when I reaction to the 12:00 AM, I want to set up the format to the next day 20140425000000, 20140425003000, 20140425020000, 20140425023000 until when I reaction to the next 12:00 AM I want to set up the new format to the day two 20140426000000, 20140426003000, 20140426010000.
 
My problem is when I'm parsing the list of time strings from my script, how I can work out the format with the date and the time?
 
 
Here is the PHP:
 
    <?php
    ini_set('max_execution_time', 300);
    $errmsg_arr = array();
    $errflag = false;
    include ('simple_html_dom.php');
    
    foreach($html->find('p[id=links]') as $element)
    {
      $program_list[ $count ] = array();
      $id_split = explode("?", $element->plaintext);
      $id_split = explode("&", $link_split[1]);
      $channels = explode("channels=",$id_split[0]);
      $channels = $channels[1];
      $id = explode("id=",$id_split[1]);
      $id = $id[1];
      $html_two = file_get_html("http://www.mysite.com/myscript.php?getime);
    
      //time1
      $time1 = $html_two->find('span[id=time1]',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];
    
    
      //time2
      $time2 = $html_two->find('span[id=time2]',0)->plaintext;
      
      $hoursMinutes = explode(":", $time2[0]);
      $hours = $hoursMinutes[0];
      $minutes = $hoursMinutes[1];
      
      $time2 = explode(" ", $time2);
      $hoursMinutes = explode(":", $time2[0]);
      $hours = $hoursMinutes[0];
      $minutes = $hoursMinutes[1];
    
    
      //time3
      $time3 = $html_two->find('span[id=time3]',0)->plaintext;
      
      $hoursMinutes = explode(":", $time3[0]);
      $hours = $hoursMinutes[0];
      $minutes = $hoursMinutes[1];
      
      $time3 = explode(" ", $time3);
      $hoursMinutes = explode(":", $time3[0]);
      $hours = $hoursMinutes[0];
      $minutes = $hoursMinutes[1];
    ?>
 
 
 
Here is the time strings:
 
    10:00 AM
    
    11:00 AM
    
    12:00 PM
    
    12:30 PM
    
    2:00 PM
    
    2:30 PM
    
    9:00 PM
    
    11:00 PM
    
    12:00 AM
    
    12:30 AM
    
    1:00 AM
    
    1:30 AM
    
    2:00 AM
    
    11:00 PM
    
    12:00 AM
    
    12:30 AM
    
    1:00 AM

 

Link to comment
https://forums.phpfreaks.com/topic/287993-how-to-work-out-the-format-with-hours/
Share on other sites

Why are you converting a perfectly readable date/time format into a non-readable hard to comprehend format?

 

If you kept the date/time in the original format you can easily modify the date using the dateTime class

A couple of examples

$date = new DateTime();
$date->add(new DateInterval('P1D')); // add 1 day to todays date
echo $date->format('Y-m-d') . "\n";


// Adds 1 hour to an existing date/time
$date = new DateTime('2014-04-22 11:23:00');
$date->add(new DateInterval('PT1H')); // add 1 day to todays date
echo $date->format('Y-m-d g:i:s') . "\n";

 

 

Example: I set up the date format from today and the time is 10:00 AM, 11:00 AM, 12:00 PM, the format is 20140424100000, 20140424110000, 20140424120000 and so on until when I reaction to the 12:00 AM, I want to set up the format to the next day 20140425000000, 20140425003000, 20140425020000, 20140425023000 until when I reaction to the next 12:00 AM I want to set up the new format to the day two 20140426000000, 20140426003000, 20140426010000.

I don't understand that due to the hard to comprehend date formats you're posting.

Because I'm parsing the time to output them in my script. 

 

If you don't understand what I want to achieve, here is for example:

10:00 AM

11:00 AM

12:00 PM

12:30 PM

2:00 PM

2:30 PM

3:00 PM

4:00 PM

5:30 PM

6:00 PM

7:00 PM

9:00 PM

11:00 PM

12:00 AM

12:30 AM

1:00 AM

1:30 AM

2:00 AM

11:00 PM

12:00 AM

12:30 AM

1:00 AM

These are the time that I'm parsing to output them in my script, so I want to convert these time into format to make it like this:

 

20140424100000
20140424110000
20140424120000
20140424123000
20140424140000 
20140424143000
20140424210000
20140424230000 
20140425000000
20140425003000
20140425010000
20140425013000
20140425020000
20140425230000
20140426000000
20140426003000
20140426010000

Here is the output:

<span id="time1">10:00 AM</span> <span id="time2">11:00 AM</span> <span id="time3">12:00 PM</span>
<span id="time4">12:30 PM</span> <span id="time5">2:00 PM</span> <span id="time6">2:30 PM</span>
<span id="time7">9:00 PM</span> <span id="time8">11:00 PM</span> <span id="time9">12:00 AM</span>
<span id="time10">12:30 AM</span> <span id="time11">1:00 AM</span> <span id="time12">1:30 AM</span>
<span id="time13">2:00 AM</span> <span id="time14">11:00 PM</span> <span id="time15">12:00 AM</span>
<span id="time16">12:30 PM</span> <span id="time17">1:00 AM</span>

Can you please tell me how to convert these time into format when parsing the time?

Edited by mark107

Thats the problem. Why are your dates in this format?

 

These are the time that I'm parsing to output them in my script, so I want to convert these time into format to make it like this:

 

20140424100000
20140424110000
20140424120000
20140424123000
20140424140000 
20140424143000
20140424210000
20140424230000 
20140425000000
20140425003000
20140425010000
20140425013000
20140425020000
20140425230000
20140426000000
20140426003000
20140426010000

 

You're making it harder for yourself with them being this way. Because they are not in a standard format which php's built in date functions will be able to understand. If you they were in a standard format like YYYY-MM-DD HH:MM:SS then you can just pass the date to a built in date function such as, dateTime and reformat the date into the 12 hour clock format.

 

In order for you to do this you're now going to have to come up with a way to parse your dates so they are presented in a standard format which PHP can then understand.

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.