mktime != UNIX_TIMESTAMP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

mktime != UNIX_TIMESTAMP

Post by anjanesh »

mktime(0, 0, 0, 4, 5, 2007); returns 1175731200
but
SELECT UNIX_TIMESTAMP( "2007-04-05" ) returns 1175711400

How come there a difference of 19800 (5.5 hrs) ?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

It is possible that your database and your server have different times.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

That almost certainly the case. Are the two on the same box? Are they using the same default timezone?
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Both are on the same box (my PC) - Using MySQL 5.0.45 and PHP 5.2.5 on Windows XP SP2
Are they using the same default timezone?
How do I check this ?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I know there is an environment var in *nix for that. PHP has an ini setting in the [date] section. Not sure about MySQL. Their manual may be able to help.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Ok - this has to be something related to GMT as Indian time is exactly 5.5 hrs ahead of GMT.

my php.ini

Code: Select all

[Date]
; Defines the default timezone used by the date functions
;date.timezone =

;date.default_latitude = 31.7667
;date.default_longitude = 35.2333

;date.sunrise_zenith = 90.583333
;date.sunset_zenith = 90.583333
Nothing related to date in my m.ini file
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Which time is correct? If it is MySQL, then uncomment the php.ini default.timezone setting then add = "{TIMEZONE}" to it where TIMEZONE is one of the timezones listed here.
Post Reply