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 8658985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:53:48+00:00 2026-06-12T15:53:48+00:00

I have a date array sorted in asc order. I want to display the

  • 0

I have a date array sorted in asc order. I want to display the date as

Oct 10,12,24 2012
Dec 12,20,24 2012
Jan 02,10,25 2013

I have got the dates as the month ie.Oct,Dec,Jan.. and the dates and year, but i want it to be displayed in the above mentioned format. I have tried the below code, but it is not giving the desired result. Can someone pls help me with this?
$CruiseDetailsSailing is the array containing the date in an ascending order.

  if (count($CruiseDetailsSailing) > 0) {
                            $date = array();
                            $month = array();
                            $Year = array();
                            for ($n = 0; $n < count($CruiseDetailsSailing); $n++) {
                                if ($CruiseDetailsSailing[$n] != "") {
                                    $date[] = date('Y-m-d', strtotime($CruiseDetailsSailing[$n]));
                                }
                            }
                        }
                        sort($date);
                        if (count($date) > 0) {
                            $temp = "";
                            $yeartemp = "";
                            for ($p = 0; $p < count($date); $p++) {
                                $month = date("M", strtotime($date[$p]));
                                $day = date("d", strtotime($date[$p]));
                                $year = date("Y", strtotime($date[$p]));
                                if ($month != $temp) {
                                    $temp = $month;
                                    ?>
                                    <li> <?php
                        echo $temp . " " . $day . ", ";
                    } else {
                        echo $day . ", ";
                    }
                    if (($p != 0) && ((date("M", strtotime($date[$p]))) == (date("M", strtotime($date[$p - 1])))) && ((date("Y", strtotime($date[$p]))) == (date("Y", strtotime($date[$p - 1]))))) {
                        echo $year;
                    }
                    if (($p != 0) && ((date("M", strtotime($date[$p]))) != (date("M", strtotime($date[$p - 1])))) && ((date("Y", strtotime($date[$p]))) != (date("Y", strtotime($date[$p - 1]))))) {
                        echo $year;
                    }
                }

Oct is the month and 10,12,24 are the months and 2012 is the year. I got the the dates as Oct 10 2012,Oct 12 2012,Oct 24 2012. I just want to display the results as Oct only once and then the dates and the year just once.
Thanks,

  • 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-06-12T15:53:49+00:00Added an answer on June 12, 2026 at 3:53 pm

    this should do:

    sort($date); // sorted input array containing dates
    
    $result_dates = Array();
    
    // bring dates in correct format
    foreach($date as $current_date) {
      $month = date("M", strtotime($current_date));
      $day = date("d", strtotime($current_date));
      $year = date("Y", strtotime($current_date));
      $result_dates[$year][$month][] = $day;
    }
    
    // output dates
    foreach($result_dates as $year => $months) {
      foreach($months as $month => $days) {
        echo $month . " " . implode(",", $days) . " " . $year . "\n";
      }
    }
    

    the following input:

    $date = Array('10/03/2012', '10/10/2012', '10/17/2012', '11/04/2012', '11/05/2012', '11/23/2012');
    

    results in:

    Oct 03,10,17 2012
    Nov 04,05,23 2012
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Date array which stored dates and time in its respective positions
I have date 2012-04-02 10:01:00 am I want to show this date in with
i have a Date array like this $dateArray = array('2012-04-11','2012-04-29','2012-04-26','2012-04-23','2012-03-21','2012-07-23','2012-12-19','2012-04-27','2012-05-12','2012-05-27','2012-05-28'); and i m using
I have some code which builds an array of date ranges. I then call
I have an array of Ruby Date objects. How can I find the newest
I have an array that I would like to sort using a date field
I have an array of hashes. Each hash looks like: 'date'=>6/23/2011, value1=>6, value2=>8, value3=>3,
I have a multi dimensional array, like this: array('name' => array('title'=>'Title','date'=>'Created')) I store it
I have this form with a date input. echo $this->Form->create('Nodata'); echo $this->Form->input('date1', array('type' =>
I have date in sting object in following format. dd/mm/yyyy I want to change

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.