Forum Moderators: coopster

Message Too Old, No Replies

PHP Time Formatting & Forms

         

guiroo

1:54 pm on Oct 2, 2004 (gmt 0)

10+ Year Member



Ok so the database column is specified as a TIME format so it stores time as HH:MM:SS in military time.

My users don't think in military time so I need the form to be standard AM/PM time. Here's a drawing of the form:

[HH]:[MM] O AM O PM

What's the best way to get the info from that form into the db in military time?

All the PHP developers I know just say, "Change the column from TIME to STRING and just store it literally." That seems like a cop out to me. All their other solutions seem rather difficult (write your own function, test for this, test for that, bla bla bla) for something that SEEMS like it would be a common task.

I'm a newbie to PHP but there's got to be an easier way.

willybfriendly

3:13 pm on Oct 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You might look at strtotime(), strftime() and related functions:

[us4.php.net...]

Depending on the task at had, I find that it is usually easiest to store anyting time related in the DB as a timestamp. Easy to manipulate/compare/etc, and easy to convert back into something readable.

WBF