Page 1 of 1

If month = x

Posted: Mon Aug 25, 2008 7:07 am
by eskimex1
Hello all,
I have looked everywhere but cant find the answer to this.

$startdate=2008-8-2

(Format of the date above is %Y-%m-%d)

So what I want to do is say if the month in $startdate is x or y, $cost=z

I tried a few things but they didnt work. Whats the best way to do this?

Please Help!!! Thanks a lot!!!
Nathan

Re: If month = x

Posted: Mon Aug 25, 2008 8:46 am
by Bill H
Show us what you've done so far, that isn't working, and someone here will be glad to help you out and tell you why it isn't working.

Re: If month = x

Posted: Mon Aug 25, 2008 8:50 am
by s.dot
2008-8-2 is a string so it needs to be enclosed in quotes
in comparison, = is wrong.. you want ==

You pretty much summed it up in your statement
if the month in $startdate is x or y, $cost=z

Code: Select all

if ($monthInStartDate == $x || $monthInStartDate == $y)
{
    $cost = $z;
}
Check out explode() to separate the date to get the month. :)

Re: If month = x

Posted: Thu Aug 28, 2008 8:06 am
by eskimex1
Thanks for the help so far guys!

So far I have

Code: Select all

$startdatemonth = explode("-", $startdate );
echo $startdatemonth[1]; // month
 
 
if ($startdatemonth[1] == "8" || $startdatemonth[1] == "9")
{
    $costper = "150";
 
This checks the month of the start date and sets the cost accordingly.
BUT I just realized that I need to check how many days of each month between two dates. (Not just the startdate)

SO,
I am using a function that gives me a list of months between the $startdate and the $enddate.

If 5 "08" and 4 "07" show up, I need to know how many of each month shows up so that I can calculate a cost.

I really hope I am making sense...