factoring2117 Posted August 11, 2010 Share Posted August 11, 2010 Hey guys, I have spent the last 36 hours trying to figure this out. I keep getting the following error: Fatal error: Call to a member function format() on a non-object in /var/www/vhosts/xxxxx.com/httpdocs/admin/defaults.php on line 51 The reason I am not using the standard date and strtotime functions is because some of my dates exceed 2038. What I have done is created an array with price and days from today within the array. You can see below where I am trying to get the timestamp for 14000 days from today. I then turn that into a date using the newdate function. I can see that this actually works on other pages on my server, I just can't figure out why it won't work here. BTW, I am using php 5.2.3. $csv .= "Payment,".newdate("m/d/Y",newstrtotime("+".$periodic[0][0]." days")).",".$row['amount'].",".count($periodic).",".$row['frequency'].",".newdate("m/d/Y",newstrtotime("+".$periodic[$perCt][0]." days"))."\n"; function newstrtotime($strtotime){ $datetime = date_create($strtotime); return $datetime->format("U"); } function newdate($format,$timestamp){ $datetime = date_create("@$timestamp"); return $datetime->format($format); } Let me know what you think. Link to comment https://forums.phpfreaks.com/topic/210436-date_create-fatal-error-call-to-a-member-function-format-on-a-non-object-in/ Share on other sites More sharing options...
bh Posted August 11, 2010 Share Posted August 11, 2010 Hi, Your "$strtotime" variable probably is not a correct format for DateTime. $csv .= "Payment,".newdate("m/d/Y",newstrtotime("+".$periodic[0][0]." days")).",".$row['amount'].",".count($periodic).",".$row['frequency'].",".newdate("m/d/Y",newstrtotime("+".$periodic[$perCt][0]." days"))."\n"; function newstrtotime($strtotime){ try { $datetime = new DateTime($strtotime); return $datetime->format("U"); } catch (Exception $e) { // echo $e->getMessage(); // if you wanna know the error message return NULL; } ... If you use the procedural constructor you cannot catch any exceptions. So thats why the OOP's mode. Link to comment https://forums.phpfreaks.com/topic/210436-date_create-fatal-error-call-to-a-member-function-format-on-a-non-object-in/#findComment-1098050 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.