Getting Time From A User

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
dwessell
Forum Commoner
Posts: 62
Joined: Fri Dec 23, 2005 2:30 pm

Getting Time From A User

Post by dwessell »

Hi all..

I'm working with a form where I'm getting a time from a user. Right now it's a drop down form, with values between 9:00am and 9:00pm, in 15 min increments.

As I'm moving to the part where I'm inserting this bit of data into MySQL.. I'm finding that it's not the best data format.. Can anyone make a suggestion as to an elegant solution for getting a time from a user, in a format that's easily workable with the databse..

Thanks to all the suggestions so far.. The input has made learning php much easier.

Thanks
David
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

have a dropdown for hours, one for minutes, one for seconds (if you need it) and one for am/pm... then generate a timestamp for inserting into the DB.

http://us2.php.net/strtotime


the function called date() reverses the timestamp back into a human readable form
(if you don't keep track of times in your head as timestamps as I do of course)
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

If you want their time, I recommend just asking for a timezone and then make calculations based upon the server time + timezone. You can keep it all in the unix timestamp format for easy manipulation.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Well I think he's prompting users for a certain time, not calculating their timezone based off what the user says their current time is
dwessell
Forum Commoner
Posts: 62
Joined: Fri Dec 23, 2005 2:30 pm

Post by dwessell »

jshpro2 wrote:Well I think he's prompting users for a certain time, not calculating their timezone based off what the user says their current time is
That's correct.. Thanks for all the tips.. I was able to succesfully build a form that took the time the user specified, the day they specified.. Do magic things with it, and insert it into the db... Thanks a ton...
Post Reply