0

EDITED:

THIS PART IS WHAT I NEED TO SOLVE:

I have a negative integer like: -10800 and I wish to convert this at my local time, which is Buenos Aires (gmt -3).

I'm using an online converter to check what date it is so I can check the results: www.4webhelp.net and it throws that -10800 is Wednesday, December 31st 1969, 18:00:00 (GMT -3) but I believe this is not correct. I was told the negative number is in my timezone which is Buenos Aires.

I also want to create from date to string using the same time format. How can I do this?

THIS PART IS SOLVED:

Among the things I tryied in order to do this, a new doubt came up when learning about mktime:

I was trying to know which is the last day for february:

$lastday = mktime(0, 0, 0, 2, 0, 2015);
echo strftime("Last day is: %d", $lastday);

And this throws that february has 31 days which is incorrect. Why is that so?

Limon
  • 1,772
  • 7
  • 32
  • 61

1 Answers1

1

If day is 0, then PHP takes the last day of the previous month, so

$lastday = mktime(0, 0, 0, 2, 0, 2015);

Gives 31st January 2015 (0th day of month 2, effectively)

As per the PHP docs

day

The number of the day relative 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).

(my emphasis)

EDIT

If you want the last day of February, use

$lastday = mktime(0, 0, 0, 2, 1, 2015);
echo 'Last day is: ', date("t", $lastday);
Community
  • 1
  • 1
Mark Baker
  • 209,507
  • 32
  • 346
  • 385
  • thanks for the answer, now I understand. But i'm still in trouble with my first question. – Limon May 28 '15 at 18:21