[drupal-devel] date conversion

Gerhard Killesreiter killesreiter at physik.uni-freiburg.de
Mon Jun 13 04:58:21 UTC 2005



On Mon, 13 Jun 2005, Gordon Heydon wrote:

> I was wondering if anyone knows of a decent method of converting dates
> from text to a time.
>
> I did look at strtotime() but it will not convert anything before Jan 1,
> 1970 which is a problem since it is going to be used for a date of birth
> field, and some people will be over 35.

Note: The valid range of a timestamp is typically from Fri, 13 Dec
     1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the
     dates that correspond to the minimum and maximum values for a
     32-bit signed integer.)

(from my version of the php manual entry for strtotime)

print strtotime("60 years ago");

gives me -774821398.

print date("d m y", strtotime("60 years ago"));

gives me 13 06 45. Only on windows you will run into problems since it
does not support negative timestamps.

>From the date() docs:
     Note: The valid range of a timestamp is typically from Fri, 13 Dec
     1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the
     dates that correspond to the minimum and maximum values for a
     32-bit signed integer). On windows this range is limited from
     01-01-1970 to 19-01-2038.

     To generate a timestamp from a string representation of the date,
     you may be able to use strtotime(). Additionally, some databases
     have functions to convert their date formats into timestamps (such
     as MySQL's UNIX_TIMESTAMP function).

>From the MySQL manual I infer that MySQL does not support negative
timestamps.

Cheers,
	Gerhard




More information about the drupal-devel mailing list