0

I have a database with date field is this format "2010.06.11. | 10:26 13"

What is need is a php array that would hold all the different dates, .i.e.

array[0] = "2010.06.09."

array[1] = "2010.06.10."

array[2] = "2010.06.11."

Currently I am doing it by selecting the whole table, then looping through the result and adding the date substr to an array if it is not already there.

But maybe there is a faster way? Thanks.

2
  • You should think about normalizing this field into a DATETIME field, if possible. :) Commented Jun 11, 2010 at 10:21
  • I'm afraid I'm already kinda locked up into this format. :) Commented Jun 11, 2010 at 10:31

1 Answer 1

2

You can directly select only the distinct dates from the database:

SELECT DISTINCT SUBSTRING(date, 1, 11) AS date_string FROM table
Sign up to request clarification or add additional context in comments.

4 Comments

thanks for the answer. "SELECT DISTINCT (TIME) FROM..." works great by filtering out the events with the same time. Yet "SELECT DISTINCT SUBSTRING(TIME, 1, 11) FROM..." somehow seems to go into a forever loop and doesn't give any results...
tried "SELECT DISTINCT(LEFT(TIME, 11)) FROM..." also won't give any results.
GOT IT! THANKS MAN! I JUST HAD TO USE $row1['LEFT(TIME,11)'] WHEN GOING THROUGH RESULTS.
Ah now I see what you mean, just add an alias to the query, see my edit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.