How to create a date range?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
idotcom
Forum Commoner
Posts: 69
Joined: Thu Mar 04, 2004 9:24 pm

How to create a date range?

Post by idotcom »

Hi All,

I have a script that I use to list events into a mysql db. I enter my dates like: 12/12/06

For each event, there is a start and end date. What I need to do is grab the earliest date event and the last date event and to create a calendar view of the events within those dates.

So, say I have these events:

Class 1: 11/10/06 - 11/15/06
Class 2: 11/16/06 - 11/18/06
Class 3: 11/19/06 - 11/25/06
Class 4: 11/26/06 - 12/15/06

How would I go about grabbing the first date and the last date? I would normally use the mysql date and select range, but the dates are in the format above in a varchar field.

The goal is to create a variable list or array of the date range between the first and last date. So when the calendar loads, the days will be colored in the ranges, because I have a color (hex) code for each event. So I want to display the event range with its color on the calendar.

Any help would be very much appreciated.

Thanks, and Happy Holidays!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Using a date format that isn't native (and doesn't automatically sort) is a complication. It's still possible to do, but requires more work. SUBSTRING_INDEX() can be used to extract and compare the individual parts of your dates.

For example

Code: Select all

SUBSTRING_INDEX(fieldName, '/', -1)
would return "06" if memory serves.
Post Reply