Timestamps

Timestamps
Difficulty: Easy
Description: Exaplains how to use Timestamps.
Author: M@ster; Date Added: 2008-10-12; Views: 14232
From members to posts and emails one good way of keeping track of them is by date, or when they were added and edited. The best way of doing this is by using timestamps.

What a timestamp does is basically gives you how many seconds its been from January 1st, 1970 and then with that you can figure out the date something added, edited, etc.

This is the code that will give you the timestamp:

$timestamp = time();
echo $timestamp;


What this does is tells how many seconds its been from January 1st, 1970.

So heres an example of what the output looks like:

Timestamp: 1223240895

and with this code you can take the timestamp and turn it into a readable date/format.

$date = date("l jS of F Y h:i:s A",$timestamp);
echo $date;


If you notice the "l jS of F Y h:i:s A" thats just telling the function on how you want to display it.

After using the code above with the timestamp above the output will be:

Sunday 5th of October 2008 02:08:15 PM

Now heres all the code together:

$timestamp = time();
echo $timestamp;

$date = date("l jS of F Y h:i:s A",$timestamp);
echo $date;


You can store a timestamp in a mysql database. Then retrieve it and easily figure out when something was added, edited or when a member registered.

-Ryan