njp
njp

Reputation: 705

Why is mktime() returning unexpected results?

$date['start'] = date("o-m-d", mktime(0, 0, 0, 1, 1, 2010));
$date['end'] = date("o-m-d", mktime(0, 0, 0, 2, 1, 2010));

Each element contains 2009-01-01, 2010-02-01 respectively. Why is the first element returning 2009, when it has been specified as 2010?

What I am trying to achieve is to specify a date I can use in a MySQL query, like:

SELECT subject, created_on FROM issues WHERE created_on BETWEEN 2010-01-01 AND 2010-02-01 ORDER BY created_on

Upvotes: 2

Views: 54

Answers (1)

Prasanth Bendra
Prasanth Bendra

Reputation: 32840

Date format should be "Y-m-d" NOT "o-m-d"

Ref: http://www.php.net/manual/en/function.date.php

o   ISO-8601 year number. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. (added in PHP 5.1.0)    Examples: 1999 or 2003
Y   A full numeric representation of a year, 4 digits   Examples: 1999 or 2003

Upvotes: 3

Related Questions