Jump to content

[SOLVED] mktime returns different value [NEWBIE]


mslinuz

Recommended Posts

Ok, as there in the subject im a newbie..in PHP.

Somehow ive got a web app that i need to modify the code a bit.

This app was written by somebody else.

Inside the code, there is a routine that retrieve a date value from a form and then

convert it into unix timestamp using mktime() then store the value to database.

To present the date value to user, the unix timestamp stored in database is converted

using date().

Here is the sample code :

<?php
   $unix="1144188000"; //sample data
   $thedate=date('d/m/y',$unix);
   echo("the date : " . $thedate); // will result will be 05/04/06
   echo("<br/>");
   $split = explode("/", $thedate);
   echo(mktime(0,0,0,$split[1],$split[0],$split[2])); //I expect the result will be the same as $unix, but apparently its not
?>

 

In above example, the mktime() does NOT return a same value as $unix as I expect it to.

tyvm for all ur kind help.

 

Cheers!!!

Link to comment
Share on other sites

i expect the last code will return a same value as $unix, since its originally created from that value.

which means its only : unix timestamp->human readable date->unix timestamp

that is what my example code is trying to do.

 

so if unix timestamp value is 123 then it should be : 123 ---> whatever ---> 123

but in the end it will never turns to 123

 

after a lil bit searching, ive found out that the guy who originally created the application lives in germany LOL...

so now i will try to do a date_default_timezone_set first before doing mktime

 

so the code will be :

 

<?php
......
date_default_timezone_set("Europe/Germany");
echo(mktime(0,0,0,$split[1],$split[0],$split[2]));

?>

 

Havent tried it yet tho, im currently not at the office.

Will report here the result by tomorrow morning.

Or maybe u guys wanna try the code a bit.

Thx for the help guys, i really appreciate it.

 

Cheers!!!

 

Link to comment
Share on other sites

it is solved.

putting :

<?php
...
date_default_timezone_set("Europe/Berlin");
...
?>

 

before doing mktime() solved the problem.

ps : the server im working now has different timezone with the orignal server in which this application was made.

 

thx for all your help.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.