Date formats

Hello everyone,

I'm wondering how to handle date fields in my app. I'm storing various dates in a mysql database. The way I'm doing it now is to display the form to the user with the date field as three separate form elements. One for the month, day, and year. In the controller, I then concatenate the fields into a new $date variable, and add it to the $POST variable. I then pass this $POST variable to the model, and it stores it in the database. When I pull a record from the database, I do the reverse. I split the returned mysql date value into the month, day, and year, and add it the three new variables to the $data result array. This is returned to the controller, which then calls the view.

I'm wondering if there is a more elegant or efficient method to handle dates?

[quote author="Sock Puppet" date="1216174646"]UNIX timestamps spring to mind immediatley Smile[/quote]

I agree. I love me some timestamps.

[eluser]Rick Jolly[/eluser]
Can you use one field for the date and add a js date picker for convenience? I hate having to select all three. You can use the following to format the date any way you like:
// example:
date('F j, Y', strtotime('2008-07-15'));
// returns July 15, 2008

Thanks for the replies. I'm leaning towards Rick's idea of a js date picker.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.