Rummaan
Rummaan

Reputation: 41

How to give fixed day in to date using php?

I want to give fixed day($day=28) to the date using php following is my code

   $next_due_bill_date = date('Y-m-d', strtotime("+1 months", strtotime($join_date)));

Upvotes: 0

Views: 290

Answers (2)

Andreas
Andreas

Reputation: 23958

Just set the date function to 28 instead of "d".

$join_date = "2018-01-01";
Echo date('Y-m-28', strtotime("+1 months", strtotime($join_date)))."\n"; 
//2018-02-28

https://3v4l.org/h5WPe

An alternative method would be to append the string after date function.

date('Y-m-', strtotime("+1 months", strtotime($join_date)))."28"; 

Upvotes: 3

Suneel Kumar
Suneel Kumar

Reputation: 1664

Just replace d with the number 28

$next_due_bill_date = date('Y-m-28', strtotime("+1 months", strtotime($join_date)));

Upvotes: 2

Related Questions