Re: Am I missing something? Why doesn't php have a 'date' variable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ross Honniball wrote:
Hello.

I've been using php for about 5 months now. One of the first things I noticed it was missing was a standard in-built manner of handling dates. I assumed that, being inexperienced, I was probably missing something and in time all would become clear.

It's a while later now and I still think it sucks that it doesn't have a standard date variable type.

Why doesn't it have a standard class or variable type to help process dates in a standard manner?

Php should offer a DATE variable type (in addition to string, int, array, object etc.).

Dates could be stored by utilising standard date functions. eg.

$birthday = SetDate('23-07-1985', 'dmy');

Use of this function would effectively declare $birthday as a field of type date. (note that I wish this was my birthday).

Standard maths could be performed on date fields for comparison. eg.

$newdate = $start_date + $birthdate - 5; // as in days

if ($date1 < $date2) ..whatever..;

And of course standard routines for formating dates, standard routines for showing time between dates / times etc.

This frustrated me so much that I recently wrote a class to emulate, as best as possible, this level of functionality, which would actually be quite adequate if Windows didn't suck. But due to some lunatic Windows limitation, it will only work on dates between 1970 and 2038. Hmmm. Nice one, Bill (are we in for another 'new millenium' problem on windows machines in 2038?).

Anyway, am I missing something, or do other people find this a glaring omission in an otherwise spiffing product?

Ross

PS note that in refering to dates above, I really mean date + time.

PSS Technical note:

As you all know, internally the only rational way to store dates is as a sequential number from an chosen starting date - eg. 1-1-1960, 1-1-1970, whatever. Prior dates are simply stored as negative numbers.
.
. Ross Honniball. JCU Bookshop Cairns, Qld, Australia.
.

You are missing a bit. Integers are generally used for Dates in PHP, using the UNIX Timestamp format. You can use strtotime() and date() to convert between timestamp and string formats. Of course, this only works for dates back to 1970.


You should have come to the list before now. ;-) There's a class in PEAR that deals with pretty much any date you'll need and has lots of funcitons for adding, subtracting, formatting, etc.

http://pear.php.net/package/Date

--
paperCrane <Justin Patrin>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux