phpmady Posted April 22, 2010 Share Posted April 22, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/199365-date-expects-parameter-2-to-be-long-whats-am-doing-wrong/ Share on other sites More sharing options...
oni-kun Posted April 22, 2010 Share Posted April 22, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/199365-date-expects-parameter-2-to-be-long-whats-am-doing-wrong/#findComment-1046322 Share on other sites More sharing options...
phpmady Posted April 22, 2010 Author Share Posted April 22, 2010 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, Quote Link to comment https://forums.phpfreaks.com/topic/199365-date-expects-parameter-2-to-be-long-whats-am-doing-wrong/#findComment-1046327 Share on other sites More sharing options...
PFMaBiSmAd Posted April 22, 2010 Share Posted April 22, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/199365-date-expects-parameter-2-to-be-long-whats-am-doing-wrong/#findComment-1046334 Share on other sites More sharing options...
phpmady Posted April 22, 2010 Author Share Posted April 22, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/199365-date-expects-parameter-2-to-be-long-whats-am-doing-wrong/#findComment-1046344 Share on other sites More sharing options...
PFMaBiSmAd Posted April 22, 2010 Share Posted April 22, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/199365-date-expects-parameter-2-to-be-long-whats-am-doing-wrong/#findComment-1046360 Share on other sites More sharing options...
phpmady Posted April 22, 2010 Author Share Posted April 22, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/199365-date-expects-parameter-2-to-be-long-whats-am-doing-wrong/#findComment-1046415 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.