GL_DATE - SQL Result in PHP
Posted in 2011
Topics: General Discussion
I have a strange Problem: GL_DATE = %d.%m.%Y sql = select field from table where datefield = '01.10.2011' I can use this (german) date formatted field to get a result set. But the datefield in the result got the format '2011-10-01'. If i use this SQL in Serverstudio, the date field in the result set is formatted like '01.10.2011' How is it possible to format the SQL result in PHP?
I'm using PDO_Informix, at least for now, and that's the behavior I see as well. A Webmaster may be able to specify a default Informix date format, but I've always just worked around the problem. When I retrieve date values from the database, I usually process them like: $working_date = date( 'm/d/Y', strtotime( $date_from_db ) ); You should be able to substitute your preferred date format for mine. See the date() and strtotime() functions in the online PHP Manual at www.php.net/manual/. If I need to update a date value in the database, I reformat to 'Y-m-d'. The above method works under the assumption that the date coming from the database is a valid date value. In general, strtotime() is *very* forgiving and will usually give you the best conversion it can without throwing an error. If you use it to process user input, I would validate the format of the user's date input separately before using strtotime() in any input processing. I typically just work with dates as strings as long as the app is just recording and displaying them. If you need to get into date arithmetic, especially with numbers of days for things like billing, be careful about time zones, daylight saving, etc. HTH, Walt. On Dec 1, 2011, at 7:20 AM, DJIHANGIROF MATTHIAS wrote: > I have a strange Problem: > > GL_DATE = %d.%m.%Y > > sql = select field from table where datefield = '01.10.2011' > > I can use this (german) date formatted field to get a result set. > But the datefield in the result got the format '2011-10-01'. > > If i use this SQL in Serverstudio, the date field in the result set is > formatted like '01.10.2011' > > How is it possible to format the SQL result in PHP? > > > ******************************************************************************* > Forum Note: Use "Reply" to post a response in the discussion forum. > -- Walt Hultgren walt@altasenta.com