# determining the day and subtracting time?

### #1 f1sh3r

f1sh3r
• New Members
• Newbie
• 3 posts
• LocationYoungstown, Ohio

Posted 23 August 2006 - 05:28 PM

im writing a function for a program im working on... there are a few different things it will do:

1. get original price (\$ofee) , and start date (\$startdate) of a course
2. if the price is > \$99, offer an "early bird" price (\$ofee - 20) if registered by 2 weeks prior (\$startdate - 14 days)

-- im good up to this point --

3. if the class starts on a saturday or sunday, the "early bird" registration would need to be 15 or 16 days prior (on a friday) because office staff doesnt work weekends

my choices?
a) find what day (mon, tue, wed...) the class starts on, and act accordingly (\$startdate - 15 or 16)
b) have something that will only allow weekdays to be displayed
c) ?

help me out please... im not that good with time manipulation. thanks a bunch.

### #2 craygo

craygo
• Staff Alumni
• 1,973 posts
• LocationRhode Island

Posted 23 August 2006 - 05:55 PM

I use the echo just to check the script. But this should do it.
```\$date = date();  //Need timestamp for other calculations
\$today = date("Y-m-d", \$date);  //formatted date
\$daylast = date("D", \$date);  // Get current day of the week
echo "Day of week: \$daylast<br>";
if(\$daylast == "Sat"){
\$twoweek = strtotime("\$today - 15 days");
} else {
if(\$daylast == "Sun"){
\$twoweek = strtotime("\$today - 16 days");
} else {
\$twoweek = strtotime("\$today - 14 days");
}
}
\$twoweeks = date("Y-m-d", \$twoweek);  //Formatted date of 2 weeks ago
echo "Two Weeks: \$twoweeks<br>";
\$daylast = date("D", \$twoweek);  //Just to check if correct can be removed
echo "Day of week: \$daylast<br>";```

Ray

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users