i have this and its in YYYY-MM-DD format now.
i need to format the callindate just for the report in the echo command to MM/DD/YYYYCode:<td><font size="1" face="Arial, Helvetica, sans-serif"><?php echo $callindate; ?></font></td>
Printable View
i have this and its in YYYY-MM-DD format now.
i need to format the callindate just for the report in the echo command to MM/DD/YYYYCode:<td><font size="1" face="Arial, Helvetica, sans-serif"><?php echo $callindate; ?></font></td>
You could use string processing...
...or the DateTime object (available in PHP 5.2+)...PHP Code:function changeDate($d){
$dateParts = explode('-',$d);
return $dateParts[1].'/'.$dateParts[2].'/'.$dateParts[0];
}
echo changeDate($callindate);
I usually store dates as a timestamp, as that's often the easiest to reformat using just the date() function.PHP Code:function changeDate($d){
$dt = new DateTime($d);
return $dt->format('m/d/Y');
}
echo changeDate($callindate);
Samba,
i tried
and i get an errorCode:function changeDate($d){
$dateParts = explode('-',$d);
return $dateParts[1].'/'.$dateParts[2].'/'.$dateParts[0];
}
<td><font size="1" face="Arial, Helvetica, sans-serif"><?php echo changeDate($callindate); ?></font></td>
Fatal error: Call to undefined function changedate() in /data/21/1/14/99/1992262/user/2178205/htdocs/ReportAllByUnit.php on line 231
i also tried the other function as well with the same result. I must be doing something wrong.
if what you pasted is where you put the function definition, you seemed to have defined it in the HTML. if this is the case, you can't do that. functions are PHP code and must be defined in PHP. it would be best to put function definitions at the very top, or very bottom, of your script. or, put them in an include file and then include them as you need them.
PHP Code:<?php
function changeDate($d){
$dateParts = explode('-',$d);
return $dateParts[1].'/'.$dateParts[2].'/'.$dateParts[0];
}
?>
<td><font size="1" face="Arial, Helvetica, sans-serif"><?php echo changeDate($callindate); ?></font></td>
kows,
i doing this
and i get this errorCode:<?php
function changeDate($d){
$dateParts = explode('-',$d);
return $dateParts[1].'/'.$dateParts[2].'/'.$dateParts[0];
}
?>
<td><font size="1" face="Arial, Helvetica, sans-serif"><?php echo changeDate($callindate); ?></font></td>
line 214 is the "function changedate($d){Code:Fatal error: Cannot redeclare changedate() (previously declared in /data/21/1/14/99/1992262/user/2178205/htdocs/ReportAllDesc.php:214) in /data/21/1/14/99/1992262/user/2178205/htdocs/ReportAllDesc.php on line 214
i dont have the function anywhere else
oh. then you did define it properly the first time. but, then there shouldn't be any reason for the script to complain the function doesn't exist. remove one of the declarations and try again?
this did it
Code:<?php
if(!function_exists('changeDate'))
{
function changeDate($d){
$dateParts = explode('-',$d);
return $dateParts[1].'/'.$dateParts[2].'/'.$dateParts[0];
}
}
?>
<td><center><font size="1" face="Arial, Helvetica, sans-serif"><?php echo changeDate($callindate); ?></font></center></td>
.. that doesn't do anything, though, unless you're defining the function twice for some reason. just remove the second definition of the function; you only need to define it once.
but where is the second declaration? what i have works but not sure why exactly.
I don't know, I don't have your code. press CTRL+F in your text editor and find changeDate. it has to be there somewhere.
I have a lot of php file with functions in them. it must be in one of those somewhere. thanks again for you help.