Jump to content


This topic is now archived and is closed to further replies.


determining the day and subtracting time?

Recommended Posts

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.

Share this post

Link to post
Share on other sites
I use the echo just to check the script. But this should do it.
[code]$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>";[/code]


Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.