mslinuz Posted September 1, 2008 Share Posted September 1, 2008 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 https://forums.phpfreaks.com/topic/122171-solved-mktime-returns-different-value-newbie/ Share on other sites More sharing options...
phpknight Posted September 1, 2008 Share Posted September 1, 2008 What are you expecting as what does it give? I would do a var_dump on split to make sure that is what you think it should be. Link to comment https://forums.phpfreaks.com/topic/122171-solved-mktime-returns-different-value-newbie/#findComment-630848 Share on other sites More sharing options...
JasonLewis Posted September 1, 2008 Share Posted September 1, 2008 It's strange, I ran some tests and it appears to be switching the day with the month. But I cannot find out why. I'm now confused. Link to comment https://forums.phpfreaks.com/topic/122171-solved-mktime-returns-different-value-newbie/#findComment-630866 Share on other sites More sharing options...
mslinuz Posted September 1, 2008 Author Share Posted September 1, 2008 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 https://forums.phpfreaks.com/topic/122171-solved-mktime-returns-different-value-newbie/#findComment-631076 Share on other sites More sharing options...
mslinuz Posted September 2, 2008 Author Share Posted September 2, 2008 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 https://forums.phpfreaks.com/topic/122171-solved-mktime-returns-different-value-newbie/#findComment-631617 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.