SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2007
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sort array by day / month, relevant to current date

    Hello,

    I have hit a hard spot with sorting an array relative to current date. I am trying to order it in such way that first elements would be March (current month of this post), each sorted by day ascending order and so on, April would come next, then May, etc. If current month would be December, then December element would be on top followed by January, February, etc ...

    Any advice would be very appreciated.

    Thanks.

  2. #2
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    This is easily done during a query.

    If it has to be done in PHP, I would convert it to timestamp, or even YYYYMMDD format works for sorting.

    But the logic is the same. You cut off any date before the current month. Then sort it ASC. it will then start the array at March and on.

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2007
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wonshikee View Post
    This is easily done during a query.

    If it has to be done in PHP, I would convert it to timestamp, or even YYYYMMDD format works for sorting.

    But the logic is the same. You cut off any date before the current month. Then sort it ASC. it will then start the array at March and on.
    Yes, you are right, this should work. I was so focused on the array that it just didn't came to me. Thank you wonshikee.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •