Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP date format issue while converting to big int

Tags:

date

php

bigint

I want to store two dates as of type big int to database I have an array which is serialized and sent array values to second form and array consists of

[checkin] => 01-07-2015
[checkout] => 03-07-2015

After converting this using

$arr['checkin'] = strtotime($arr['checkin']);
$arr['checkout'] = strtotime($arr['checkout']);

I'm getting value as 1435689000 1435861800 respectively, which are one day less than actual date values.

and just to inform in my server if my code is

<?php echo date('d-m-y', '1435689000');?>

then the output will be 01-07-15, and if I tried to use gmdate function as follows

echo gmdate('d-m-y', '1435689000');

The output will be 30-06-15

I am not able to figure out what is the issue is will you please help. Thank you..

like image 331
Shridhar Avatar asked Sep 08 '26 20:09

Shridhar


1 Answers

You need to learn the difference between both of these function

1) date

string date ( string $format [, int $timestamp = time() ] )

Returns a string formatted according to the given format string using the given integer timestamp or the current time if no timestamp is given. In other words, timestamp is optional and defaults to the value of time().

2) gmdate

string gmdate ( string $format [, int $timestamp = time() ] )

Identical to the date() function except that the time returned is Greenwich Mean Time (GMT).

If you've seen the another function it already define that both are identical but gmdate returns it in GMT

If you echo both of these functions along with time you'll understand the difference

echo date('Y-m-d H:i:sP',1435689000);//2015-07-01 00:00:00+05:30

echo gmdate('Y-m-d H:i:sP',1435689000);//2015-06-30 18:30:00+00:00

its because according to the GMT timezone your current time is +0530 ahead of the GMT. Thus the output for both are correct but the difference is the timezones

like image 138
Narendrasingh Sisodia Avatar answered Sep 10 '26 12:09

Narendrasingh Sisodia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!