Avatar of savsoft
savsoftFlag for India

asked on 

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
PHP

Avatar of undefined
Last Comment
Ray Paseur
ASKER CERTIFIED SOLUTION
Avatar of cyberstalker
cyberstalker

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

$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();
Avatar of Hugh McCurdy
Hugh McCurdy
Flag of United States of America image

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.
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

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.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

Best regards, ~Ray
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo