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
If month = x
Moderator: General Moderators
- Bill H
- DevNet Resident
- Posts: 1136
- Joined: Sat Jun 01, 2002 10:16 am
- Location: San Diego CA
- Contact:
Re: If month = x
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
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
Check out explode() to separate the date to get the month. 
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;
}
Last edited by pickle on Mon Aug 25, 2008 3:05 pm, edited 1 time in total.
Reason: Typed "strong" - he mean't "string"
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.
Re: If month = x
Thanks for the help so far guys!
So far I have
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...
So far I have
Code: Select all
$startdatemonth = explode("-", $startdate );
echo $startdatemonth[1]; // month
if ($startdatemonth[1] == "8" || $startdatemonth[1] == "9")
{
$costper = "150";
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...