'How to extract time from timestamp?
I have extract date from timestamp but how to I extract time from timestamp? I had doing some research but I can found it. Can someone help me work out from this?
This is my sql code:
$stmt = "SELECT id, date(creation_timestamp) as date, time(creation_timestap) as time, text FROM "._CONST_TBL_COMMUNITY_COMMENT;
if($rs = $db->Execute($stmt))
{
while($rsa = $rs->FetchRow())
{
array_push($arrResult, array(
"id" => $rsa['id'],
"date" => $rsa['date'],
"time" => $rsa['time'],
"text" => $rsa['text']
));
}
}
And this is my result which without time(creation_timestamp) as time
in above sql statement:
Array ( [0] => Array ( [id] => 1 [date] => 2014-05-14 [text] => test test test test )
Solution 1:[1]
I didn't look at your PHP code. In standard SQL, you can cast a timestamp as time.
select cast(current_timestamp as time) as just_time . . .
Solution 2:[2]
If you work directly with PHP you can just submit the Timestamp:
$time=date("H:i",$timestamp);
$date=date("d.m.Y",$timestamp);
$datezime=date("d.m.Y H:i",$timestmap);
For more information: Date (PHP Docs)
For SQL: from_unixtime (mySQL Docs)
You can then use it like this:
from_unixtime(timestamp, '%Y %D %M %h:%i:%s')
Solution 3:[3]
Sorry guy. I found my mistake. I write wrong for my database filed name which on time(creation_timestap) as time
. It suppose time(creation_timestamp) as time
.
Sorry for my mistake and trouble you guy's time.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Mike Sherrill 'Cat Recall' |
Solution 2 | D. Schalla |
Solution 3 | user3517652 |