Jump to content

date() expects parameter 2 to be long? whats am doing wrong


Recommended Posts

Hi,

 

In my localhost there is no problem, but when am running in server i gettting this error

 

Warning: date() expects parameter 2 to be long

 

 


$Course_Date_Beginning = date("d-m-Y",$temp['Course_Date_Beginning']);

 

 

In my database: the value is 1272315600

 

When i use the function:

 

gettype($temp['Course_Date_Beginning');

 

am getting the type:STRING

So whats am doing wrong? plz help me

If you're sure it's just a timestamp then try this:

 

date("d-m-Y",strtotime($temp['Course_Date_Beginning']));

 

Although it would be useful to var_dump the row to see what is actually in it. Typecasting should make strings not matter, you shouldn't be getting that error unless it's not a time stamp.

If you're sure it's just a timestamp then try this:

 

date("d-m-Y",strtotime($temp['Course_Date_Beginning']));

 

Although it would be useful to var_dump the row to see what is actually in it. Typecasting should make strings not matter, you shouldn't be getting that error unless it's not a time stamp.

 

the value i am getting from form is

 

echo $_POST['Course_Date_Beginning'];//20-04-2010

 

after that i use this line to save in db

 

$Course_Date_Beginning = strtotime($_POST['Course_Date_Beginning']);

 

This is what am doing,

Could you use var_dump() on $temp['Course_Date_Beginning'] like oni-kun suggested so that we can see exactly what is in it right before the line where the error is occurring.

 

By definition, all data fetched from a database is a string data type, but due to php's automatic type casting this is usually not a problem. There are probably 100's of thousands of php web sites that are doing the same thing you are trying without any warning messages, so either what is actually in $temp['Course_Date_Beginning'] is not what you think it is or you have a php version with a bug in it.

Could you use var_dump() on $temp['Course_Date_Beginning'] like oni-kun suggested so that we can see exactly what is in it right before the line where the error is occurring.

 

By definition, all data fetched from a database is a string data type, but due to php's automatic type casting this is usually not a problem. There are probably 100's of thousands of php web sites that are doing the same thing you are trying without any warning messages, so either what is actually in $temp['Course_Date_Beginning'] is not what you think it is or you have a php version with a bug in it.

 

Hi,

 

Using var_dump am getting this,

string(10) "1271106000"

 

 

Any way now i have hide the error by doing this is in server...i think i masked it...but i am loking for the fact what am doing wrong...

if($temp['Course_Date_Beginning']!="")
{
$tpl->assign("Course_Date_Beginning", date("d-m-Y",$temp['Course_Date_Beginning']));
}
else
{
$tpl->assign("Course_Date_Beginning","");
}

 

Now i am not getting error, but i am not sure, am i right?

 

Thank You

 

 

I'm going to guess that your data has always contained empty values and the problem has always existed, but your localhost development system has error_reporting/display_errors set to hide warning messages (and probably notice messages as well.)

 

If you expect your data to have empty values, then yes you would need to add logic like you just posted to correctly handle the case where $temp['Course_Date_Beginning'] is empty.

 

You should actually have error_reporting set to E_ALL and display_errors set to ON in your master php.ini on your development system so that all php errors are reported and displayed.

I'm going to guess that your data has always contained empty values and the problem has always existed, but your localhost development system has error_reporting/display_errors set to hide warning messages (and probably notice messages as well.)

 

If you expect your data to have empty values, then yes you would need to add logic like you just posted to correctly handle the case where $temp['Course_Date_Beginning'] is empty.

 

You should actually have error_reporting set to E_ALL and display_errors set to ON in your master php.ini on your development system so that all php errors are reported and displayed.

 

Thank you for ur time for me, as u said i have changed my error_report to show.

 

Take care,

Cheers

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.