# Date Support

- Thread: https://externals.io/message/11839
- Original archive: https://news-web.php.net/php.internals/11839
- Started by Jason Garber on 2004-08-03T02:36:14+00:00
- Messages: 16
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #11839 — Jason Garber — 2004-08-03T02:36:14+00:00

URL: https://externals.io/message/11839#11839

Hello internals,

  Not to take away from the wonderful and lively "GOTO" discussion,
  but...  I've got a couple simple questions.

  1. Is there a particular reason that PHP does not have a really good
  set of functions for dealing with true date and time types (i.e. not
  timestamps)?

  2. I think that good date and time handling in PHP would be a
  large plus.  MySQL provides, imho, a very effective set of tools for
  handling dates.  I think that this style of date handling, where the
  standard format was YYYY-MM-DD HH:MM:SS would be an ideal way to go.
  Comments?

  3. If there is no good reason for not adding this set of functions
  to the PHP core, what would be the method of designing an acceptable
  set of functions?

  PHP is a feature packed language, but it's strange that this does not
  exist in the core.  Thanks for your time.

-- 
Best regards,
 Jason Garber                      mailto:jason@ionzoft.com
 IonZoft, Inc.

---

## #11840 — George Schlossnagle — 2004-08-03T02:40:45+00:00

URL: https://externals.io/message/11839#11840 · In reply to: #11839

> Hello internals,
>
>   Not to take away from the wonderful and lively "GOTO" discussion,
>   but...  I've got a couple simple questions.

What's insufficient in `strtotime()` and `strftime()`?

George

---

## #11841 — Wez Furlong — 2004-08-03T02:41:09+00:00

URL: https://externals.io/message/11839#11841 · In reply to: #11839

http://pecl.php.net/package-info.php?package=Date

It's not in the core because it is still relatively young.
Maybe in a future release...

--Wez.


> Hello internals,
> 
>   Not to take away from the wonderful and lively "GOTO" discussion,
>   but...  I've got a couple simple questions.
> 
>   1. Is there a particular reason that PHP does not have a really good
>   set of functions for dealing with true date and time types (i.e. not
>   timestamps)?
> 
>   2. I think that good date and time handling in PHP would be a
>   large plus.  MySQL provides, imho, a very effective set of tools for
>   handling dates.  I think that this style of date handling, where the
>   standard format was YYYY-MM-DD HH:MM:SS would be an ideal way to go.
>   Comments?
> 
>   3. If there is no good reason for not adding this set of functions
>   to the PHP core, what would be the method of designing an acceptable
>   set of functions?
> 
>   PHP is a feature packed language, but it's strange that this does not
>   exist in the core.  Thanks for your time.
> 
> --
> Best regards,
>  Jason Garber                      mailto:jason@ionzoft.com
>  IonZoft, Inc.

---

## #11845 — Jason Garber — 2004-08-03T03:07:49+00:00

URL: https://externals.io/message/11839#11845 · In reply to: #11841

Hello Wez,

I must be missing something...  I went to the link and couldn't find
any documentation.  I downloaded it and all the .tgz contained were a
couple of .php scripts?

-- 
Best regards,
 Jason                            mailto:jason@ionzoft.com

Monday, August 2, 2004, 10:41:09 PM, you wrote:

WF> http://pecl.php.net/package-info.php?package=Date

WF> It's not in the core because it is still relatively young.
WF> Maybe in a future release...

WF> --Wez.

WF> On Mon, 2 Aug 2004 22:36:14 -0400, Jason Garber <jason@ionzoft.com> wrote:
> > […]

---

## #11846 — Jason Garber — 2004-08-03T03:08:17+00:00

URL: https://externals.io/message/11839#11846 · In reply to: #11840

Hello George,

  Because they both operate on an integer timestamp...

  two things:
    SELECT CURDATE() + INTERVAL 7 MONTH;
    echo strtotime("7/12/1900");

  Timestamps are fine for things that are happening within a very limited
  range of dates.  How do you add a given number of months to a date?
  how do you get the day of week for a given date?  These are the
  types of functions that I am thinking of.

-- 
Best regards,
 Jason                            mailto:jason@ionzoft.com

Monday, August 2, 2004, 10:40:45 PM, you wrote:


GS> On Aug 2, 2004, at 10:36 PM, Jason Garber wrote:

> > […]

GS> What's insufficient in `strtotime()` and `strftime()`?

GS> George

---

## #11847 — Robert Amos — 2004-08-03T03:19:25+00:00

URL: https://externals.io/message/11839#11847 · In reply to: #11846

> Hello George,
> 
>   Because they both operate on an integer timestamp...
> 
>   two things:
>     SELECT CURDATE() + INTERVAL 7 MONTH;
>     echo strtotime("7/12/1900");
>
>   Timestamps are fine for things that are happening within a very limited
>   range of dates.  How do you add a given number of months to a date?
>   how do you get the day of week for a given date?  These are the
>   types of functions that I am thinking of.
> 

echo strtotime("now +7 months");
echo date('l', strtotime('2004-10-02')); || echo strftime('%A',
strtotime('2004-10-02')); (latter supports locales)

http://php.net/strtotime
http://php.net/strftime
http://www.gnu.org/software/tar/manual/html_chapter/tar_7.html

-bok

---

## #11850 — Wez Furlong — 2004-08-03T03:30:11+00:00

URL: https://externals.io/message/11839#11850 · In reply to: #11845

Urgh, blame PEAR for that ;-)
There is a PECL date extension that you can obtain from our CVS
(see http://www.php.net/anoncvs.php):

cvs -d :pserver:cvsread@cvs.php.net:/repository co pecl/date
cd pecl/date
phpize
./configure
make install
[ add date.so to php.ini ]

--Wez.


> Hello Wez,
> 
> I must be missing something...  I went to the link and couldn't find
> any documentation.  I downloaded it and all the .tgz contained were a
> couple of .php scripts?
> 
> --
> Best regards,
>  Jason                            mailto:jason@ionzoft.com
> 
> Monday, August 2, 2004, 10:41:09 PM, you wrote:
> 
> WF> http://pecl.php.net/package-info.php?package=Date
> 
> WF> It's not in the core because it is still relatively young.
> WF> Maybe in a future release...
> 
> WF> --Wez.
> 
> 
> 
> WF> On Mon, 2 Aug 2004 22:36:14 -0400, Jason Garber <jason@ionzoft.com> wrote:
> > […]

---

## #11851 — Jevon Wright — 2004-08-03T06:10:17+00:00

URL: https://externals.io/message/11839#11851 · In reply to: #11839

I always wished that PHP had VB's set of operators on dates/times... (and
also in SQL): year(), month(), `date()`, time_serial(), and the like. Yes, you
can do it with date("...", $x); but then it's just awkward to remember all
the operators.

Also, I'd always wished that PHP would have support for dates after 32 bit
(2037)... when do you think Pecl's Date would get into PHP?

Jevon

----- Original Message ----- 
From: "Jason Garber" <jason@ionzoft.com>
To: <internals@lists.php.net>
Sent: Tuesday, August 03, 2004 2:36 PM
Subject: [PHP-DEV] Date Support


> Hello internals,
>
>   Not to take away from the wonderful and lively "GOTO" discussion,
>   but...  I've got a couple simple questions.
>
>   1. Is there a particular reason that PHP does not have a really good
>   set of functions for dealing with true date and time types (i.e. not
>   timestamps)?
>
>   2. I think that good date and time handling in PHP would be a
>   large plus.  MySQL provides, imho, a very effective set of tools for
>   handling dates.  I think that this style of date handling, where the
>   standard format was YYYY-MM-DD HH:MM:SS would be an ideal way to go.
>   Comments?
>
>   3. If there is no good reason for not adding this set of functions
>   to the PHP core, what would be the method of designing an acceptable
>   set of functions?
>
>   PHP is a feature packed language, but it's strange that this does not
>   exist in the core.  Thanks for your time.
>
> -- 
> Best regards,
>  Jason Garber                      mailto:jason@ionzoft.com
>  IonZoft, Inc.

---

## #11855 — Derick Rethans — 2004-08-03T07:32:15+00:00

URL: https://externals.io/message/11839#11855 · In reply to: #11839

> Hello internals,
>
>   Not to take away from the wonderful and lively "GOTO" discussion,
>   but...  I've got a couple simple questions.
>
>   1. Is there a particular reason that PHP does not have a really good
>   set of functions for dealing with true date and time types (i.e. not
>   timestamps)?

I'm about 60% done with this ;-)

>   2. I think that good date and time handling in PHP would be a
>   large plus.  MySQL provides, imho, a very effective set of tools for
>   handling dates.  I think that this style of date handling, where the
>   standard format was YYYY-MM-DD HH:MM:SS would be an ideal way to go.
>   Comments?

This is one format that I can parse... but the major format will be a
"timestamp" of some sort.

regards,
Derick

---

## #11856 — Derick Rethans — 2004-08-03T07:32:48+00:00

URL: https://externals.io/message/11839#11856 · In reply to: #11840

>
> 
>
> > […]
>
> What's insufficient in `strtotime()` and `strftime()`?

They behave badly and are OS dependent... which makes it quite a mess in
the code too; which is very hard to maintain now.

Derick

---

## #11857 — Derick Rethans — 2004-08-03T07:34:24+00:00

URL: https://externals.io/message/11839#11857 · In reply to: #11851

> I always wished that PHP had VB's set of operators on dates/times... (and
> also in SQL): year(), month(), `date()`, time_serial(), and the like. Yes, you
> can do it with date("...", $x); but then it's just awkward to remember all
> the operators.

Good point, I'll add that to the list.

> Also, I'd always wished that PHP would have support for dates after 32 bit
> (2037)... when do you think Pecl's Date would get into PHP?

The thing I'm working on should work for larger ranges than the 32bit
range, except that I can't do DST information outside the range, as the
timezone information files can not contain this :I

Derick

---

## #11860 — John Lim — 2004-08-03T08:34:18+00:00

URL: https://externals.io/message/11839#11860 · In reply to: #11851

Hi

There's a library that i wrote that supports timestamps > 2037.

It takes advantage of the fact that PHP converts integers to floats on
overflow. It uses the nearly the same api as `date()` and `mktime()`, to make
porting easier.

Regards, John

See http://phplens.com/phpeverywhere/adodb_date_library

"Jevon Wright" <jevon@jevon.org> wrote in message
news:011601c47920$8d116ba0$0a00a8c0@home.jevon.org...
> I always wished that PHP had VB's set of operators on dates/times... (and
> also in SQL): year(), month(), `date()`, time_serial(), and the like. Yes,
you
> can do it with date("...", $x); but then it's just awkward to remember all
> the operators.
>
> Also, I'd always wished that PHP would have support for dates after 32 bit
> (2037)... when do you think Pecl's Date would get into PHP?
>
> Jevon
>
> ----- Original Message ----- 
> From: "Jason Garber" <jason@ionzoft.com>
> To: <internals@lists.php.net>
> Sent: Tuesday, August 03, 2004 2:36 PM
> Subject: [PHP-DEV] Date Support
>
>
> > […]

---

## #11861 — Marcus Boerger — 2004-08-03T08:44:57+00:00

URL: https://externals.io/message/11839#11861 · In reply to: #11860

Hello John,

how does that help? I mean sizeof(double) == 4 == sizeof(int/32).
In other words the bitsize is the same. Only you get an exponent.
The result is that you loose time information accuracy.

regards
marcus

Tuesday, August 3, 2004, 10:34:18 AM, you wrote:

> Hi

> There's a library that i wrote that supports timestamps > 2037.

> It takes advantage of the fact that PHP converts integers to floats on
> overflow. It uses the nearly the same api as `date()` and `mktime()`, to make
> porting easier.

> Regards, John

> See http://phplens.com/phpeverywhere/adodb_date_library

> "Jevon Wright" <jevon@jevon.org> wrote in message
> news:011601c47920$8d116ba0$0a00a8c0@home.jevon.org...
> > […]
> you
> > […]




-- 
Best regards,
 Marcus                            mailto:helly@php.net

---

## #11862 — John Lim — 2004-08-03T09:32:38+00:00

URL: https://externals.io/message/11839#11862 · In reply to: #11861

Hi Marcus,

For 32 bit architectures, normally:

  sizeof(float) == 4, sizeof(double) == 8 or 10

So there is no floating point overflow fortunately.

E.g. http://www.iota-six.co.uk/c/b3_float_double_and_sizeof.asp

PS: i  think the `date()` and `mktime()` functions could be extended using the
algorithms described in the date library, if anyone is interested. It would
make date( ) and `mktime()` much more user friendly.

"Marcus Boerger" <helly@php.net> wrote in message
news:1912137764.20040803104457@marcus-boerger.de...
> Hello John,
>
> how does that help? I mean sizeof(double) == 4 == sizeof(int/32).
> In other words the bitsize is the same. Only you get an exponent.
> The result is that you loose time information accuracy.
>
> regards
> marcus
>
> Tuesday, August 3, 2004, 10:34:18 AM, you wrote:
>
> > […]
>
> > […]
>
> > […]
make
> > […]
>
> > […]
>
> > […]
>
> > […]
(and
> > […]
Yes,
> > […]
all
> > […]
bit
> > […]
good
> > […]
not
> > […]
for
> > […]
the
> > […]
go.
> > […]
acceptable
> > […]
not
> > […]
>
>
>
>
> -- 
> Best regards,
>  Marcus                            mailto:helly@php.net

---

## #11863 — Marcus Boerger — 2004-08-03T09:55:26+00:00

URL: https://externals.io/message/11839#11863 · In reply to: #11862

Hello John,

ups you're right of course, i must be dreaming.
Maybe you should talk to Derick about the internal functions
and you should also have a look at pecl/date.

marcus

Tuesday, August 3, 2004, 11:32:38 AM, you wrote:

> Hi Marcus,

> For 32 bit architectures, normally:

>   sizeof(float) == 4, sizeof(double) == 8 or 10

sizeof(long double) == 10

> So there is no floating point overflow fortunately.

> E.g. http://www.iota-six.co.uk/c/b3_float_double_and_sizeof.asp

> PS: i  think the `date()` and `mktime()` functions could be extended using the
> algorithms described in the date library, if anyone is interested. It would
> make date( ) and `mktime()` much more user friendly.

> "Marcus Boerger" <helly@php.net> wrote in message
> news:1912137764.20040803104457@marcus-boerger.de...
> > […]
> make
> > […]
> (and
> > […]
> Yes,
> > […]
> all
> > […]
> bit
> > […]
> good
> > […]
> not
> > […]
> for
> > […]
> the
> > […]
> go.
> > […]
> acceptable
> > […]
> not
> > […]




-- 
Best regards,
 Marcus                            mailto:helly@php.net

---

## #11879 — Sara Golemon — 2004-08-03T19:07:48+00:00

URL: https://externals.io/message/11839#11879 · In reply to: #11851

> Also, I'd always wished that PHP would have support for dates after 32 bit
> (2037)...
>
Funny my Athlon64 reports dates just fine up until 12/31/2147483647  (I
blame glibc for not going clear out to 0x7FFFFFFFFFFFFFFF -- silly signed
ints...)

-Sara
