If month = x

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eskimex1
Forum Newbie
Posts: 3
Joined: Mon Aug 25, 2008 6:59 am

If month = x

Post 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
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Re: If month = x

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: If month = x

Post 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. :)
Last edited by pickle on Mon Aug 25, 2008 3:05 pm, edited 1 time in total.
Reason: Typed "strong" - he mean't "string"
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
eskimex1
Forum Newbie
Posts: 3
Joined: Mon Aug 25, 2008 6:59 am

Re: If month = x

Post 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...
Post Reply