Bruce Gust
asked on
This is a mess...I need to return a date...
Here's the scenario. I have within my URL the number of a week in year 2015. I want to use the setISO functionality to return a user friendly date.
I want to keep said function in a class, so here's what I'm thinking:
...and then on my page, I've got this:
The error I get is Catchable fatal error: Object of class DateTime could not be converted to string in C:\wamp\www\SouthArea\GANT \index.php on line 6
I could use a procedural approach, but I want to use the OOP dynamic. Where am I blowing it?
I want to keep said function in a class, so here's what I'm thinking:
class DateCalc {
public function arley_week($year, $week_number) {
$date = new DateTime();
$date->setISODate($year, $week_number);
return $date;
}
}
...and then on my page, I've got this:
$anchor_week=new DateCalc;
$the_week=$anchor_week->arley_week(2015,2);
echo $the_week;
The error I get is Catchable fatal error: Object of class DateTime could not be converted to string in C:\wamp\www\SouthArea\GANT
I could use a procedural approach, but I want to use the OOP dynamic. Where am I blowing it?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just curious... Are you sure you completely understand the PHP and ISO meanings of week numbers? There are some quirky things about them that can produce very counter-intuitive results. You might get a better result if you would describe the application needs and ask about best practices for handling the date / time values for the application. Just a thought...