NYCPHP Meetup

NYPHP.org

[nycphp-talk] mktime

Hans Zaunere zaunere at yahoo.com
Wed Jun 11 14:55:41 EDT 2003


--- "Sexton, David" <David.SextonJr at ubs.com> wrote:
> Hi all,
>  
> I've run into an issue. Supposedly the mktime function will return a UNIX
> timestamp while factoring in the timezone offset on the host machine (I
> assume this because there is a gmmktime function as well for passing GMT
> dates).

Note that factoring of the timezone concerns the date *given* and not the
timestamp returned.  UNIX timestamps have no timezone.

> Anyways, I have written a function that calculates trade dates. I am
> currently reproducing the function in VB, and I noticed that the timestamp
> returned by PHP's mktime function is 5 hours ahead of the timestamp
> returned in VB.

As it should be, I believe.  VB is probably in the wrong here, and returns a
timestamp that is offset by your timezone.  Nevertheless, VB's version of the
date() function probably expects this behavior, and so usually there aren't
any problems. ( note that NY is of course -0200 )

> The other thing is that I then use the PHP date function to create a
> formatted date using the UNIX timestamp returned by mktime. This date seems
> to be correct, and the function is working as designed. So my second
> question is: If mktime is not factoring the time zone offset on my host, is
> the date function compensating for it and returning the correct trade date?

Exactly.  That's the great thing about UNIX timestamps - they aren't timezone
specific, and so timezone adjustments are done only when creating a human
readable date and time.  Plus, heck, VB is on Windows, how could you expect
it to handle UNIX timestamps correctly  :)  Just out of curiosity, is PHP
running on Windows or a UNIX flavor during these tests?

H




More information about the talk mailing list