Good Morning All...

This may be a simple question but hopefully someone can give me a specific answer...

I know I can set a date based on the current date + or - a specified number of days

$created = date("Y-m-d H:i:s", time()) ;
$dist_date = date("Y-m-d", strtotime($created.'+4 days')) ;// distribute in 4 days

But what I really need to do is to specify a date as say the 20th of the current month
(used to calculate future payouts that are earned, but will not be paid out until the 20th)

Is there a way to specify the strtotime so it would indicate the 20th, regardless of which day of the month it is calculated?

Recommended Answers

All 3 Replies

It is strange... I can search and search until I reach the point of asking a question in here...

Then as soon as I ask the question, I seem to find an answer... Not always sure if it is the BEST answer, but it is an answer.

# this gets you 20th day of current month and year
$pay20 = mktime(0, 0, 0, date("m")  , date("20"), date("Y"));

$dist_date = date("Y-m-d", $pay20) ;// distribute on the 20th

print "<br>dist_date : ".$dist_date;

gives me the result dist_date : 2014-06-20

So, I do have an answer, but is there a better way to do it?

Thanks in advance for any positive feedback
Dougls

solution is to get off the day part from the date and display 20 inplace of it. Like you did it so i Hope it a way but why you need to have something like that?

Because we have multiple types of commissions that are earned based on activity, and some are paid out weekly, some on the 10th of each month some on the 15th of each month and some on the 20th of each month...

So, on the first of the month, I query the earnings records for ever individual commission earned in the previous month in each category, and generate a distribution record to be paid on whichever date it is paid on... in this case it is to be paid on the 20th, so that is the date that needs to be recorded in the distribution record.

Then every day a cron job runs to check for any commissions to be paid out that day, and processes the distribution records for that date...

sounds complicated, but it is pretty simple, and gives us the latitude to add new bonuses and or commissions whenever we want, and they will be processed in the same way.

All distribution records are generated between 2 and 20 days in advance of being paid out to give us sufficient time to verify the accuracy of the distributed funds before they leave the company account.

I actually realized I could do that in a single line.

$dist_date = date("Y-m-d",(mktime(0,0,0,date("m"),date("20"),date("Y")))) ;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.