Page 1 of 1
Simple calendar event system
Posted: Mon Mar 15, 2010 4:29 pm
by Cirdan
Dates and times are so much fun to work with

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?
Re: Simple calendar event system
Posted: Mon Mar 15, 2010 5:11 pm
by lshaw
You can use a mysql DATETIME Column in the format YYYY-MM-DD HH-MM-SS
eg.
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.
Re: Simple calendar event system
Posted: Mon Mar 15, 2010 5:14 pm
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.
Re: Simple calendar event system
Posted: Mon Mar 15, 2010 11:44 pm
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/