Forum Moderators: coopster
$thisdate=date("m,d,Y",strtotime("24 Jan 2005")); echo $thisdate."<br />"; echo mktime(00,01,12,$thisdate)."<br />"; echo mktime(00,01,12,01,24,2005)."<br />"; echos:
01,24,2005 <= $thisdate 1104912072 <= first mktime using $thisdate 1104825672 <= 2nd mktime using same data directly Using:
echo strftime("%c",mktime(00,01,12,$thisdate)); echo strftime("%c",mktime(00,01,12,01,24,2005)); it is clear that
mktime() is stuck on "today" as the day, even though its reading the month and year correctly. mktime() seems to be having trouble getting the day right when I use data from the date(..,strtotime()) method. Similarly, if I set a variable to hold the time info, i.e.
$thistime="00,01,12"; and then try $getdate=$thistime.$thisdate; echo mktime($getdate); I consistently echo the current time and date.
Anyone care to venture a guess as to why?
Running Win 98SE 4.10, PHP 4.2.3, Apache 1.3.12
everything passed to mktime is optional, so...
int mktime ( [int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]] )
when you call this
mktime(00,01,12,$thisdate)
that is only 4 params so you are passing 01,24,2005 as the month, since that isn't a proper format for month mktime does now, as it does when it gets bad params or we get that fancy dat e from 1969.
<added>editing is pretty short, well I can only gues, mine is infinite in this forum ;)
$thisrec=explode(":",$logentry[1]); $thisd=explode("/",$thisrec[0]); switch ($thisd[1]) { case "Jan": $thismo="01";break; case "Feb": $thismo="02";break; } $thisdate=mktime($thisrec[1],$thisrec[2],$thisrec[3],$thisd[0],$thismo,$thisd[2]); to get the right timestamp, but it seems like such a waste.
Thank you for your response, jatar_k. Because I'm a bit anal in this way, would you give an explanation for why $thisdate in my first example isn't being parsed by mktime(), but is instead being treated as a single parameter despite the included commas?
because that's what it is, not very technical but it is really just a syntax question more than anything else
if a function is expecting 2 values as parameters you can't do
$myparams = 'val1,val2';
$var1 = somefunction($myparams);
it will die with a 'wrong number of parameters on line x' or something like that. The only reason it seemd to work for mktime is that all of the params are optional so it didn't kill itself.
If php was going to parse through the contents of every var all the time it would die screaming in an infinite loop or maybe the server would just burst into flames. :)
[webmasterworld.com...]