how can i reformat "thedate" filed to look mm-dd-yyyy instead of default mysql results yyyy-mm-dd????while($row = mysql_fetch_assoc($result))
{
echo '<tr><td>'.$row['AttendanceID'].'</td><td>'.$row['thename'].'</td><td>'.$row['theposition'].'</td><td>'.$row['emp#'].'</td><td>'.$row['thenote'].'</td><td>'.$row['thedate'].'</td><td>'.$row['theday'].'</td><td>'.$row['time_in'].'</td><td>'.$row['time_out'].'</td><td>'.$row['break_hrs'].'</td><td>'.$row['reg_hrs'].'</td><td>'.$row['worked_hrs'].'</td><td>'.$row['work_description'].'</td></tr>';
}
change date format!
Moderator: General Moderators
change date format!
ok, i ask the user for a date from date picker then i make a format date so that it will convert it to mysql format yyyy-m-d then i check the database for records. before printing the records i want to format the date again to show as m-d-Y because it doesnt look good for a user to see 2009-03-17 for example!!
Re: change date format!
Try this functions:
You may modify the functions to suit your purpose.
Code: Select all
//Your date to mysql date
function date_to_mysql($date) {
//if $date is not numeric, assume it's in textual format
if (!is_numeric($date)) {
$date=strtotime($date);
}
return date('Y-m-d H:i:s',$date);
}
//mysql to your own date
function myDate($date){
//if $date is not numeric, assume it's in textual format
if (!is_numeric($date)) {
$date=strtotime($date);
}
return date('m-d-Y H:i:s',$date);
}
Last edited by temidayo on Wed Mar 18, 2009 6:02 am, edited 1 time in total.
Re: change date format!
Thanks but i am sorry to say that i am new to php! i believe the one iam interested in is the second function. but where to put that with my code! sorry again!
Re: change date format!
In your code, do this..
Code: Select all
date('Y-m-d H:i:s',strtotime($row['thedate']));
instead of
$row['date'];
Re: change date format!
Your new code could look like this:
Code: Select all
function myDate($date){
//if $date is not numeric, assume it's in textual format
if (!is_numeric($date)) {
$date=strtotime($date);
}
return date('m-d-Y H:i:s',$date);
}//function myDate($date)
while($row = mysql_fetch_assoc($result))
{
echo '<tr><td>'.$row['AttendanceID'].'</td><td>'.$row['thename'].'</td><td>'.$row['theposition'].'</td><td>'.$row['emp#'].'</td><td>'.$row['thenote'].'</td><td>';
echo myDate($row['thedate']);
echo'</td><td>'.$row['theday'].'</td><td>'.$row['time_in'].'</td><td>'.$row['time_out'].'</td><td>'.$row['break_hrs'].'</td><td>'.$row['reg_hrs'].'</td><td>'.$row['worked_hrs'].'</td><td>'.$row['work_description'].'</td></tr>';
}
Re: change date format!
Thanks all for the help. its working now 
Re: change date format!
With date() and strtotime() function you can easily concert date between PHP and MySQL date format.
Here is an example:
http://n1scripts.com/php_scripts/php_co ... ipts&id=21
Here is an example:
http://n1scripts.com/php_scripts/php_co ... ipts&id=21
Re: change date format!
I thought this thread was supposed to be closed.
The poster said it was working fine, so why bring the dead thread up again?
The poster said it was working fine, so why bring the dead thread up again?