Jump to content

date_create - Fatal error: Call to a member function format() on a non-object in


factoring2117

Recommended Posts

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.

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.