Click to See Complete Forum and Search --> : Timestamps....


Daniel T
06-10-2004, 06:18 PM
I have never really used the time() function before, just the date() function, so I am not familiar with it. I have the following code:<?php
echo time();
?>
And it returns this:1086909287How the hell am I supposed to get a time our of THAT?? I really don't understand this function...

DanUK
06-10-2004, 06:29 PM
Hiya, to get a response, like 17:03:33 (H, M, S), you'd use:


<?php echo date ("H:i:s"); ?>


I think you've got the UNIX time there that you pasted, and there's scripts to enterpret it, but for PHP to display it like I mentioned, use the above.

More info at http://php.net/date

HTH.

Regards,

Daniel T
06-10-2004, 06:38 PM
Well, does using time("H:i:s") return a value that is storable in a MySQL field with the TIMESTAMP type? Because I thought that a timestamp could only contain numbers. Would I just use time("His")?

DanUK
06-10-2004, 06:44 PM
Hiya,

Sorry, I didn't gather from your first post what you were wanting to achieve.

I did a little search, and found this document which I believe is what you're looking for, and gives you syntaxes.

http://dev.mysql.com/doc/mysql/en/DATETIME.html

You might want to try to emulate some of those...

Regards,

The Cheat
06-10-2004, 07:40 PM
thats a unix timestamp

it's very useful- you can easily convert it to any format you want

i usually store a unix timestamp in a database, then convert it to the date format of my choice when it is being retrieved from the database.

heres an example of converting a unix timestamp to a normal looking date

<?php
//Time Formatting
$timeformat = "l dS of F Y h:i:s A"; //see http://php.net/date for parameters

//get timestamp
$time = time();

//echo converted time
echo gmdate("$timeformat", "$time");
?>

pyro
06-10-2004, 08:31 PM
Originally posted by The Cheat
i usually store a unix timestamp in a database, then convert it to the date format of my choice when it is being retrieved from the database.So do I... Always.

Daniel T
06-10-2004, 09:20 PM
Originally posted by The Cheat
thats a unix timestamp

it's very useful- you can easily convert it to any format you want

i usually store a unix timestamp in a database, then convert it to the date format of my choice when it is being retrieved from the database.

heres an example of converting a unix timestamp to a normal looking date

<?php
//Time Formatting
$timeformat = "l dS of F Y h:i:s A"; //see http://php.net/date for parameters

//get timestamp
$time = time();

//echo converted time
echo gmdate("$timeformat", "$time");
?>
Thank you The Cheat! That was very helpful. Also, is there anyway to control wether it outputs a 6, 8, 12, or 14 digit timestamp?

pyro
06-10-2004, 09:23 PM
No, because the timestamp is simply the number of seconds since Unix Epoch...

Daniel T
06-10-2004, 09:25 PM
OOOOHHHH!! I get it! Wicked cool! :p