PHP project: convert times to numbers Jul24 '04

One of the major obstacles I had when creating this new version of my site was how to differentiate a group of timestamps, and order them chronologically – from earliest to latest – and then number them accordingly (01, 02, 03, etc).

Let’s say I have written three blog entries for today. The three entries all have different (and unique) times.

The timestamp of each entry makes EVERY entry unique because there is no possible way of having multiple entries with the same date AND time. Sure, they could easily have the same date (which is the case for each of the three entries), but their times are completely unique, because there is no possible way (that I know of) where I could update SO FAST, that more than one entry had the exact same time. It’s impossible. Agree?

The timestamp I am referring to is the MySQL default time format, which is hour:minute:second. An example looks like this: 21:43:09, which is 9:43 PM, and 9 seconds, but rarely are seconds mentioned.

Let’s say the times for each of my three updates, throughout the day, are as follows:

I updated my blog with new entries at each of those times.

Now... how can I CONVERT each of these times to numbers, starting with 1, and ending with however many timestamps there are for the day – in this case, 3. AND... they have to be in chronological order, from earliest to latest.

It’s more complicated than it appears.

This is what I want to end up with:

And, obviously, if there are more than three entries for the given day, the next consecutive number would be used for each consecutive entry.

How did I auto–generate these numbers?

Categories: PHP

Add Feedback (view all)

Leave feedback

Feedback

Input format: The editor controls below will assist with Markdown syntax.

Status

Sub-status

Your info

matthom is published and produced by Matt Thommes - an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from Chicago. Never one to conform, Matt intends to promote the effect the web has on our lives, in an effort to intensify, instruct, and clarify all that is happening around us.

Contact Matt

Similar Entries

Stats

411 unique visits since August 2008

Syndicate

Advertisements