Formatting MySQL date....
Posted: Fri Oct 17, 2003 11:06 am
I came thru a strange problem while using TIMESTAMP in MySQL.
When I tried formatting date using date() function I got a strange results.
I had something Like This......
this out puts something like this..
So I wrote a lil' (a bit stupid but working) function..
Okay.. so the Question is ...
Is there any simpler way to format a TIMESTAMP value which MySQL stores ??
It's important for me to know so I can stop bringing shame to by showing off such a price of coding.
When I tried formatting date using date() function I got a strange results.
I had something Like This......
Code: Select all
<?php
echo "Original Value : ".$row_rsUsers['loginTime'];
echo "Formatted Value : ".date('d.m.Y, G:i', $row_rsUsers['loginTime'])
?>So it was a mess... and I had to get the proper value anyhow...Original Value : 20031017211729
Formatted Value : 19.01.2038, 8:44
while the correct value should be : 17.10.2003, 21:17
So I wrote a lil' (a bit stupid but working) function..
Code: Select all
<?php
function formatdate($date)
{
$theDate = array(
"year" => substr($date,0,4),
"month" => substr($date,4,2),
"date" => substr($date,6,2),
"hour" => substr($date,8,2),
"min" => substr($date,10,2),
"sec" => substr($date,12,2)
);
$fdate = $theDate['date'].".".$theDate['month'].".".$theDate['year'].", ".$theDate['hour'].":".$theDate['min']." ";
$fdate .= date('a', mktime($theDate['hour'],$theDate['min'],$theDate['sec'],$theDate['month'],$theDate['date'],$theDate['year']));
return $fdate;
}
formatdate($row_rsUsers['loginTime']);
?>I know I know, This can be called a very amatuer programming, but it worked for me... as a matter of fact I wasn't happy when i finished coding this one.So this function outputs what I wanted it to...
17.10.2003, 21:17 am
Okay.. so the Question is ...
Is there any simpler way to format a TIMESTAMP value which MySQL stores ??
It's important for me to know so I can stop bringing shame to by showing off such a price of coding.