Solved

Display date, based on date... something

Posted on 2013-01-08
4
229 Views
Last Modified: 2013-01-08
Hi,

I pay my affiliates twice per month (1st and 15th) and would like a function to output the next payment date.

How should I go about that?
0
Comment
Question by:kgp43
  • 2
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
Slimshaneey earned 500 total points
ID: 38756235
You could do something like this:

//===
//If day part of month is 15 or greater, next payment will be first of next month
//===
$now = getdate();

if($now['day'] >= 15){
//Your next payment is on the 1st

$nextmonth = ($now['mon'] + 1) % 13 + 1;
$year = $now['year'];
if($nextmonth == 1)
    $year++;
$thefirst = gmmktime(0, 0, 0, $nextmonth, $year);

//Here, use date function to format the timestamp in thefirst var

}else{
//Your next payment is on the 15th

$thefifteenth = gmmktime(0, 0, 15, $now['mon'], $now['year']);
}

Open in new window


I havent tested this but it should get you there abouts for your needs
0
 

Author Comment

by:kgp43
ID: 38756366
Will this work? (got an idea after looking at your code)

function NextPaymentDate() {
	
	# Next payment is the 1st
	if(date('d') >= 15) {

		$month = date('Month', strtotime('+1 month'));
		$year = date('Y',strtotime('+1 month'));

		return $month." 1st, ".$year;

	}else{
		
		# Next payment is on the 15th
		return date('F')." 15th, ".date('Y');
	}
}

Open in new window

0
 
LVL 11

Expert Comment

by:Slimshaneey
ID: 38756378
That should work just fine! I just went with timestamps as wasnt sure how you wanted to display the dates.
0
 

Author Comment

by:kgp43
ID: 38756399
Perfect, thanks for your help :)
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question