Jump to content

determining the day and subtracting time?


f1sh3r

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.
Link to comment
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]

Ray
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.