TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Time Issues? (http://www.talkphp.com/absolute-beginners/4514-time-issues.html)

Randy 06-10-2009 01:39 AM

Time Issues?
 
So im running a timestamp with my mysql and im using

PHP Code:

time() 

but im getting an output like this:

Quote:

1244597808
How would i go about making this a legit time like: 21:03

Thanks,
Randy

Wildhoney 06-10-2009 01:53 AM

That is the Unix timestamp of the current time and date. It is the amount of seconds since midnight of January the 1st, 1970. It is pretty standard in the programming world because it takes everything into consideration, leap years included.

It contains all the data you require for the time and date, with a precision of a second.

If we're to convert that Unix timestamp you supplied then we would convert it using the date function, in the specified format. All the available formats are described on its PHP.net page.

Just from that data you supplied I can tell you that is 02:36:48 using the following line of code:

php Code:
echo date('H:i:s', 1244597808);

Unfortunately, I am not sure on the date because I've not requested that information, but the timestamp still contains that data.

To see the time and the date for that timestamp I can do the following to tell you what it is:

php Code:
echo date('d-m-Y H:i:s', 1244597808);

I now know that timestamp is the 10th of June, 2009 at 02:36:48. This is also timezone specific because to me there are still the same amount of seconds since 1970, as there are to you, because the changes in the timezone are relative.

At this very second the timestamp is 1244598646. In Google we can see that is the equivalent to a very precise 39.4397936 years.

Edit: Sorry, I probably misread your post as I am ever so tired. In MySQL you can do the following:

sql Code:
SELECT CURTIME();

Runar 06-10-2009 10:26 AM

Great and simple explanation, Wildhoney! Even thou you answered the wrong question ;)


Yours, Runar

Randy 06-11-2009 03:44 AM

He did answer it differently then i had expected but he gave me info on how to use that time format and just how put it correctly.

Randy 06-11-2009 03:46 AM

He did answer it differently then i had expected but he gave me info on how to use that time format and just output it correctly.

Tanax 06-11-2009 10:54 AM

Just a sidenote, you don't have to explicitly write the numbers there if you want the current time. You can just do this:

php Code:
echo date('d-m-Y H:i:s', time());

Salathe 06-11-2009 11:13 AM

Quote:

Originally Posted by Tanax (Post 25221)
Just a sidenote, you don't have to explicitly write the numbers there if you want the current time. You can just do this:

php Code:
echo date('d-m-Y H:i:s', time());

If you're going to do that, just leave out the second argument entirely, date('d-m-y H:i:s');


All times are GMT. The time now is 04:51 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0