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,

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;

 

}

?>

Link to comment
Share on other sites

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;

}

}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.