Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

creating dates from 3-tuples

0 views
Skip to first unread message

yawnmoth

unread,
Nov 25, 2005, 2:24:38 AM11/25/05
to
Given a 3-tuple of some day, month, and year that checkdate would
return true for, how would I go about converting that day, month, and
year to something like September 3, 1997 using gmdate?
mktime(0,0,0,$month,$day,$year) doesn't seem to work as often as it
should (it'll occasionally return September 2, 1997 when it should
return September 3, 1997).
mktime(0,0,0,$month,$day,$year)+date('Z')+60*60*date('I') seems to work
occasionally, too, but again, it doesn't work all the time. Would
gmmktime(0,0,0,$month,$day,$year) work all the time? It works with the
limited testing I've been able to subject it to, thus far, but I don't
know if it'd work all the time.

Alternatively, what about
gmmktime(0,0,0,$month,$day,$year)+date('Z')+60*60*date('I')? With the
limited testing that I've done on that, it seems to work, too...

As for why I'm using gmdate - I'm trying to modify an existing
application, and am trying to use an existing function that already
uses gmdate. I don't want to change gmdate to date because, although
that might (or might not; I haven't tried it), I'd risk breaking other
things that used that same function...

Ewoud Dronkert

unread,
Nov 25, 2005, 4:29:10 AM11/25/05
to
yawnmoth wrote:
> year to something like September 3, 1997 using gmdate?
> mktime(0,0,0,$month,$day,$year) doesn't seem to work as often

Timezone artefact. Don't mix mktime() and gmdate(). Use mktime() and
date(), or gmmktime() and gmdate(), depending on what the parameters
represent. See http://php.net/gmmktime

--
E. Dronkert

0 new messages