A JM Posted September 24, 2009 Share Posted September 24, 2009 When reading the date from MySQL and displaying them in the field on my form the format is yyyy-mm-dd. How can I change that to display mm/dd/yyyy? I currently display the records date field like so: value="<?php echo htmlentities($row_rstdetail['filed_date'], ENT_COMPAT, 'utf-8'); ?>" Thanks. A JM, Quote Link to comment Share on other sites More sharing options...
smerny Posted September 24, 2009 Share Posted September 24, 2009 do it when you are pulling it from the database so instead of just GET date use GET DATE_FORMAT(date,'%m/%d/%Y') AS date Quote Link to comment Share on other sites More sharing options...
A JM Posted September 25, 2009 Author Share Posted September 25, 2009 Since I'm using a SELECT * that would mean I would have to resort to pulling each field in the SQL statement...hmmm.. Could I write a custom function? I'm not positive about how a PHP is processed so I'm sure if that would work or not..? Thanks for the suggestion. Quote Link to comment Share on other sites More sharing options...
A JM Posted September 25, 2009 Author Share Posted September 25, 2009 Maybe something like this? <?PHP function ($theValue){ list($date, $month, $year) = explode("-", $theValue); if (checkdate($month, $date, $year)) { $pol_expdate = $month . '/' . $date . '/' . $year; $theValue = $pol_expdate; return $theValue; }else{ return $theValue; } ?> Quote Link to comment Share on other sites More sharing options...
A JM Posted September 25, 2009 Author Share Posted September 25, 2009 Ultimately I fixed it with the following function.. let me know if anyone sees a problem with it. <?php function ConvertDate($theValue) { if ($theValue != NULL) { list($year, $month, $date) = explode("-", $theValue); $theValue = $month . '/' . $date . '/' . $year; return $theValue; }else{ return NULL; } } ?> Quote Link to comment Share on other sites More sharing options...
5kyy8lu3 Posted September 25, 2009 Share Posted September 25, 2009 that works. you can also use php's date() function too if you prefer, it's probably faster and less code. date("Y/m/d", $DateFromTable); //kinda like this Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.