Roy Barten Posted February 17, 2009 Share Posted February 17, 2009 Hello, i build the following function: function ConvertToDateTime($number,$calendartype) { if ($calendartype == "week"){ $time = date("$number:00:00 2009-03-02"); $date = strtotime($time); } if ($calendartype == "month"){ echo "maand"; $day = date("00:00:00 2009-03-$number"); $date = strtotime($day); } } Now the result of the following function is placed into $date. But into another function i need this result, so i have function calles function1. And function 1 calls function2 to convert an variable into a date, and then function1 has to continue and have to call function3 who also needs function2. How do i do this? Please help! Link to comment https://forums.phpfreaks.com/topic/145549-solved-php-function-please-help/ Share on other sites More sharing options...
Mchl Posted February 17, 2009 Share Posted February 17, 2009 Functions work best, when they return values function ConvertToDateTime($number,$calendartype) { if ($calendartype == "week"){ $time = date("$number:00:00 2009-03-02"); $date = strtotime($time); } if ($calendartype == "month"){ echo "maand"; $day = date("00:00:00 2009-03-$number"); $date = strtotime($day); } return $date; } And then <?php $date = ConvertToDateTime(12,"week"); anotherfunction($date); ... Link to comment https://forums.phpfreaks.com/topic/145549-solved-php-function-please-help/#findComment-764114 Share on other sites More sharing options...
cola Posted February 17, 2009 Share Posted February 17, 2009 Here solution. I hope that this help you function ConvertToDateTime($number,$calendartype) { if ($calendartype == "week"){ $time = date("$number:00:00 2009-03-02"); $date = strtotime($time); } if ($calendartype == "month"){ echo "maand"; $day = date("00:00:00 2009-03-$number"); $date = strtotime($day); } return $date; } function function2 () { $date= ConvertToDateTime($number,$calendartype); } Link to comment https://forums.phpfreaks.com/topic/145549-solved-php-function-please-help/#findComment-764115 Share on other sites More sharing options...
Roy Barten Posted February 17, 2009 Author Share Posted February 17, 2009 Thanks, the problem is solved! Link to comment https://forums.phpfreaks.com/topic/145549-solved-php-function-please-help/#findComment-764123 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.