Mktime error()

This thing run in FF but not in Opera. It displays the ff.

Warning: mktime() expects parameter 4 to be long, string given in C:\xampp


        $Date = str_replace("/","-",$Date);
	$Month = substr($Date,0, 2)."<br/>";	
	$Day = substr($Date, strpos($Date, '-') + 1, 2)."<br/>";	
	$Year = substr($Date, strpos($Date, '-') + 4);	
	echo(date("m-d-Y",mktime(0,0,0,$Month,$Day,$Year))."<br />");

Is it the browser or my codes? thanks.

Hello,

a couple of changes in your code:

$Date = '10/10/2011';
$Date = str_replace("/","-",$Date);
$Month = substr($Date,0, 2)."<br/>";	
$Day = substr($Date, strpos($Date, '-') + 1, 2)."<br/>";	
$Year = substr($Date, strpos($Date, '-') + 4);	
	
echo date("m-d-Y", mktime(0,0,0,(int) $Month,(int) $Day,(int) $Year));

Anyway, PHP is processed on server side, so the result should be exactly the same throughout all browsers.


$Date = "10/10/2011";
echo(date("m-d-Y",strtotime($Year))."<br />");

That one liner should work, though test very carefully 9/10/2011 and 10/9/2011 to check which you mean to be the 9th October, and importantly which PHP understands to be the 9th October – make sure they match or you may find yourself having to [fphp]explode/fphp the incoming $Date first.

The error is gone and it works now but the format I’m looking is not the same as the result. I’m planning to save it in my db, so I should follow the Y-m-d format which mysql understand, but when I tried the code it appears to be 1970-01-01. what’s the problem in it?

I followed this code

$Date = str_replace("/","-",$Date);
$Month = substr($Date,0, 2)."&lt;br/&gt;";	
$Day = substr($Date, strpos($Date, '-') + 1, 2)."&lt;br/&gt;";	
$Year = substr($Date, strpos($Date, '-') + 4);	
echo(date("Y-m-d",mktime(0,0,0,(int)$Year,(int)$Month,(int)$Day))."&lt;br /&gt;");

Ok, this end my agony. I just change its format and viola.
THank you.

$Date = str_replace(“/”,“-”,$Date);
$Month = substr($Date,0, 2).“<br/>”;
$Day = substr($Date, strpos($Date, ‘-’) + 1, 2).“<br/>”;
$Year = substr($Date, strpos($Date, ‘-’) + 4);
$Date = date(“Y-m-d”,mktime(0,0,0,$Month,$Day,$Year)).“<br />”;
echo $Date;

Sorry, SB


$Date = "10/10/2011";
echo date("Y-m-d",strtotime($Date)) ;