Nikhil Pawar
Nikhil Pawar

Reputation: 301

unable to get correct using strtotime("2015-02-14") function in php

I want timestamp of date that I use in strtotime() function. But it gives me timestamp of day before that date. Suppose if I use:

echo strtotime("2015-02-14");

then it give me 1423868400 this, which is timestamp of "2015-02-13".

Please help me.

Upvotes: 2

Views: 139

Answers (2)

tomloprod
tomloprod

Reputation: 7882

Maybe is a problem with the timezone. You can set your timezone as follow:

date_default_timezone_set('UTC');
echo strtotime("2015-02-14"); // Shows 1423872000

EDIT:

// With your timezone
date_default_timezone_set('Asia/Kolkata');
echo strtotime("2015-02-14"); // Shows 1423852200


You can read more about date_default_timezone_set method here: http://php.net/manual/en/function.date-default-timezone-set.php

And also more about strtotime method also here: http://php.net/manual/en/function.strtotime.php

Upvotes: 2

JBA
JBA

Reputation: 2899

You probably have a timezone issue here. By giving a date without any hour, it assumes you're saying 0h0min0sec... whether the server is before or after greenwich might change the final result ;)

Try to setTimeZone to your working current time zone before issuing your script, that could be the solution.

Upvotes: 0

Related Questions