[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 297
  • Last Modified:

php function to converts seconds into timestamp

i need any php function which can converts seconds into timestamp
for eg.

$time=time();

or

$time="12356679";

now i want to convert the time into complete timestamps in format 2011-10-04 22:41:15
0
savsoft
Asked:
savsoft
1 Solution
 
cyberstalkerCommented:
Use the date function.

date('Y-m-d H:i:s', $time);
0
 
Dave BaldwinFixer of ProblemsCommented:
$today = date("Y-m-d H:i:s", $time);  http://us.php.net/manual/en/function.date.php

It is not a good idea to name variables with the names of functions like $time=time();
0
 
Hugh McCurdyCommented:
Dave makes an excellent point about variable naming.  For a timestamp of the current time, I typically use $now.  Ideally the variable you use should provide information about the purpose of the variable.  $lastVisitTime, $accountCreated, $lastPurchaseTime, $bookDueDate.
0
 
Ray PaseurCommented:
Seconds ARE timestamps!

Something in format 2011-10-04 22:41:15  is not a timestamp.  It is an ISO-8601 DATETIME string.  Please take a moment to read over this article.  I think you will find it helpful.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

Best regards, ~Ray
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now