Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6753249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:08:17+00:00 2026-05-26T13:08:17+00:00

I have a list of dates in an array (in unix integer format). I

  • 0

I have a list of dates in an array (in unix integer format).

I have sorted these numbers in ascending order. Done.

Now, I am looping through every element using the foreach command.

I am trying to add a echo '<p>'; every time the hour changes in the data…so I am trying to get a list of the dates, sorted, and with a <p> every hour so they are in hourly blocks…

How to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:08:17+00:00Added an answer on May 26, 2026 at 1:08 pm

    Is this what you are looking for?

    //list of unix timestamps 
    $timeStamps = array();
    //false data for testing
    for($i=1;$i<=30;$i++){
        $timeStamps[] = strtotime("+".($i*10)." minutes");
    }
    
    //remember the last value.
    $new = '';
    $last = '';
    //loop through the timestamps
    foreach($timeStamps as $ts){
        //generate a hour string for this ts
        $new = date('d-M-Y H', $ts);
        //if this hour string is not the same as the last hour string echo p tag
        if($new != $last){
            echo '<p>';
        }
        //set $last to the new hour string for next loop.
        $new = $last;
    
        //echo the date
        echo date('d-M-Y H:i', $ts).'<br />';
    }
    

    I also included the date in the hour string to prevent problems with the date changing. for example if a timestamp is for 1-NOV-2011 1:00am and the next timestamp is for 2-NOV-2011 1:00am just checking the hour will not echo a <p>. including the date will.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array List<SomeObject> which contain ascending order of dates (and some more
I have a list of dates stored in MySQL using PHP. These were stored
I have a list of dates for an event in the following format 13/04/2010
i have an array of vacation dates. These are always going to be weekdays.
I have a list of dates that a machine has worked on, but it
I need to display a list of dates, which I have in a table
I have created a list view that displays the names and dates of items
If I have a pair of dates, and I want to generate a list
I have a javascript array of dates, in the form {year:'2010',month:'6',day:'23'} I need to
Let's say I have two list of dicts: dates = [{'created':'2010-12-01'},{'created':'2010-12-02'},....] elts = [{'created':'2010-12-01',

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.