Simple calendar event system

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
Cirdan
Forum Contributor
Posts: 144
Joined: Sat Nov 01, 2008 3:20 pm

Simple calendar event system

Post by Cirdan »

Dates and times are so much fun to work with :banghead: I want to create a simple event calendar which allows me to post events with a specific date and time, and allowing recurring events. I'm trying to figure out how to best store the time and date information. For everything else on the site I use unix timestamps. I think for this specific case, it would be better to store the data differently to make it easier to query. I planned to just split every thing up, having a day, month, year column, a time column, and the recursion column. Is there a better way to do this?
lshaw
Forum Commoner
Posts: 69
Joined: Mon Apr 20, 2009 3:40 pm
Location: United Kingdom

Re: Simple calendar event system

Post by lshaw »

You can use a mysql DATETIME Column in the format YYYY-MM-DD HH-MM-SS
eg.

Code: Select all

2010-03-15 22-06-30
This should be simple enough to query by date.
I would use a unix timestamp and the php strtotime() function for this though. Like:

Code: Select all

strtotime($time) //make any date format a timestamp 03.04.01,05/06/10, tomorrow, today, next monday
This function is VERY useful for me.
A user can type in today or next tuesday and you can still find matching events. To check for errors, strtotime returns false if a timestamp is not produced.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Simple calendar event system

Post by califdon »

I would stick with the timestamp, since you can do whatever you may need to do, even though it takes a bit more code, sometimes. If you split the representation of dates and times, you're inventing the whole timestamp concept all over again, and when, later down the line, you find that you need to do something else, you may not be able to do it. That's why someone invented the timestamp, years ago, and why it has been used without substantial change ever since.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Simple calendar event system

Post by Christopher »

I think Luke has an iCalendar library that has a lot of this functionality. You might want to try it.

http://code.google.com/p/qcal/
(#10850)
Post Reply