Dates and times are such a pain in the butt

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
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Dates and times are such a pain in the butt

Post by Luke »

I'm building a system that a user can add/modify/delete events in a calendar. Now there is a start date, a start time, an end date, and an end time. The trouble comes because the event doesn't necessarily have to have an "end time". It does have to have a start time, and a start date, and if they don't enter an end date it will just get set to the same as the start date.

Since there doesn't have to be an end time. I store start_date, end_date, start_time and end_time, and allow end_time to be null. So now whenever I load an event or add an event, I have to check "is this am or pm?" (0 or 12) and then set all that information and then set "checked='checked'" in my am/pm drop down as well as converting the time from hh:mm:ss to hh:mm for the user and then converting it BACK to go into the database.

I also have to convert the time from yyyy-mm-dd to mm-dd-yyyy while displaying to the user in the text input, and then convert back to yyyy-mm-dd to put it into the database.

My question is this: Is there an easier way?? :?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

DATE_FORMAT()?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Dates and times are such a pain in the butt

Post by Christopher »

The Ninja Space Goat wrote:My question is this: Is there an easier way?? :?
Not really .. I would recommend using javascript pop-up date and time widgets. They reduce entry errors. But you still need to do some conversion.
(#10850)
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Code: Select all

if ($end_date == null) $end_date = $start_date;
and unix timestamps.
Post Reply