Thursday, 12 June 2008

php strtotime returning 1970-01-29 - Adding month to date

Adding a month to a date
I was having problems using strtotime. The line i was using was

$next_available_date_end = strtotime("+2 months", next_available_date_start);

and the result I was getting was the date

I'm not sure why but opted to use mktime instead.
Here is how I accomplished this

$original_date = 2008-12-01;

$original_date_array = explode('-', $original_date ); // splits the date up

list($temp_year, $temp_month, $temp_day) = $original_date_array; // puts the array into the value year,month, day in sequence required

$temp_month++; // adds a month - we can do this because PHP will interperate 13 as the January in the next year

$date_a_month_on= date('Y-m-d', mktime(0, 0, 0, $temp_month, $temp_day, $temp_year));

for more on dates check

Monday, 2 June 2008

Passing variables around a class

I'm expecting a fair few of my following blogs to be about using Classes.
It's one of the tools of PHP that I have not really used. Functions yes but
not Classes, I have however hve been trying to use other peoples classes.
This I feel is bad pracise without fully understanding how and why classes
should be used.
I have been using the class activecalender which can be found at for a booking script. The changes I have been making to
class have been hacks to the code itself. After some studying into classses
it seems this is not the best practise but what i should do is make an
extended class, known as a child class.

'class myclass extends myparent'

Child classes then inherent member functions and member variables from its
parent. I will be coming back to this topic in a future blog, firstly I will
be looking at repackaging some of my own code into classes.
My original problem that has created this tipping point was that I could not
pass variables around the class . The solution is very simple.
in the Call up to the class set the value of the variable you wish to pass
around the class

$cal->item =$item;

from inside the class set up variable

var = $item;

and form inside the function


it's that easy!!!