Web Hosting Talk







View Full Version : [PHP] Playing with dates


Tomer
09-02-2005, 05:29 AM
Learn how to play and use dates with PHP.

This tutorial will teach you the basics on how to use time & date with PHP.

Ever wondered how time works on the internet, very simple actually. All times are measured by the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).

The measurement is called a timestamp, which contains the large date number.

You can get the timestamp of the current time with the following function:

<?php

$timestamp = mktime();

?>


Now that we have the timestamp, we can transform it to our favorite format. For this, we'll need to use the date() function.

Lets see an example:

<?php

$timestamp = mktime();

// Lets show this format: day - month - year
echo date("d - m - Y", $timestamp);

?>


To view the rest of this tutorial, please click here (http://www.swedesignz.com/php.html?id=11).

- Tomer

arkin
09-04-2005, 09:32 PM
There is only 1 more part to this tutorial.
Pointless.

ZmiyGorinich
09-05-2005, 09:45 AM
All of this you can see at http://php.net in documentation section

jetson
09-13-2005, 07:10 AM
You can also simply use the time() function rather than mktime to get a current UNIX timestamp.

You can also set the users timezone using sentenv() to modify the TZ environment variable

Some of the really cool functions get lost:

http://php.net/strtotime - make a timestamp from man common string date formats

etc

LimpBagel
09-26-2005, 01:34 PM
Yes, definetely read the documentation on php.net

The date function has many cool features like returning the number of days in the given month, whether or not the year is a leap, what number week you are in, various text represantations of the day or month.

Lots of fun stuff

CaseyG
10-22-2005, 01:29 AM
Know pretty much all of this, but I bet some people will put this to good use!

Minodragon
01-13-2006, 09:31 PM
I agree. This tutorial was really not needed.