FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » mktime() changes days when it should't
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: mktime() changes days when it should't [message #172423 is a reply to message #172414] Thu, 17 February 2011 09:33 Go to previous messageGo to previous message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma:
Senior Member
El 17/02/2011 1:43, TAXI escribió/wrote:
> I write this couse of http://bugs.php.net/bug.php?id=54005 - As you can
> see Derik says it's not a bug (in PHP itself) and links me to here for
> support.
>
> P.S. Couse of Deriks last sentence I changed the script so that it
> passes 0 as hour to mktime() but that doesn't change anything.

The test code in your bug report is really hard to follow but you appear
to be trying to perform date calculation by adding raw amounts of
seconds and months.

That might be useful if time was the same all around Earth, days always
had the same amount of seconds and years always had the same amount of
days. Unluckily, none of these statements are true.

Time calculations are harder than you think. I suggest you have a look
at the relative formats provided by strtotime():

http://es.php.net/strtotime
http://es.php.net/manual/en/datetime.formats.relative.php

> I think the problem with february is that mktime() doesn't know that february only has 28 days?

See the day parameter at http://es.php.net/mktime

«The number of the day relevant to the end of the previous month. Values
1 to 28, 29, 30 or 31 (depending upon the month) reference the normal
days in the relevant month. Values less than 1 (including negative
values) reference the days in the previous month, so 0 is the last day
of the previous month, -1 is the day before that, etc. Values greater
than the number of days in the relevant month reference the appropriate
day in the following month(s).»

An example:

echo date('Y-m-d H:i:s', mktime(0, 0, 0, 2, 31, 2011));

.... prints 2011-03-03 00:00:00


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Almost done - Just need a way to assign a variable
Next Topic: Grate opportunities to earn money from online!
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Oct 05 21:43:37 GMT 2024

Total time taken to generate the page: 0.06468 seconds