Jump to content

[SOLVED] Reading dates from MySQL format problem..


A JM

Recommended Posts

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,

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.

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;

 

}

?>

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;

}

}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.