using getdate php function inside class returns error
Posted: Thu May 03, 2007 3:28 pm
feyd | Please use
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I'm trying to call a DateAdd function from inside a class I'm building. The problem I'm having is I get the following error when trying to access the function:
"A non well formed numeric value encountered in" - followed by the line number which is the code line from the function:"$date_time_array = getdate($date);". I believe this is because the class can't find the native php getdate() function. The parameters I'm passing are (d, 90, 2007-05-16), so I know they're OK, or appear to be OK. I tried putting the $this-> in front of the getdate() function, but got an error telling me it couldn't find the getdate function.
Is the getdate the problem, or am I missing something.
thanks,
TomCode: Select all
function DateAdd($interval, $number, $date) {
$date_time_array = getdate($date);
$hours = $date_time_array['hours'];
$minutes = $date_time_array['minutes'];
$seconds = $date_time_array['seconds'];
$month = $date_time_array['mon'];
$day = $date_time_array['mday'];
$year = $date_time_array['year'];
switch ($interval) {
case 'yyyy':
$year+=$number;
break;
case 'q':
$year+=($number*3);
break;
case 'm':
$month+=$number;
break;
case 'y':
case 'd':
case 'w':
$day+=$number;
break;
case 'ww':
$day+=($number*7);
break;
case 'h':
$hours+=$number;
break;
case 'n':
$minutes+=$number;
break;
case 's':
$seconds+=$number;
break;
}
$timestamp= mktime($hours,$minutes,$seconds,$month,$day,$year);
return $timestamp;
}feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]