1

I have a subscription module, it rebills a term on every month on first day, But here I want to rebill on Wednesday of first full week of a month. I need to write this in php code.

Currently I am getting the First Wednesday of month. here is the snippet

<?php
//Get the first Wednesday of July, 2019
echo date("j, d-M-Y", strtotime("first Wednesday 2019-07"));
//Result is: Wednesday, 02-Jul-2019
?>

Actual result: First Wednesday in first week of a month but it starts from 02 is Wednesday.

Expected result, First Wednesday in first full week of a month. Month should starts from Monday to Friday. It should be full week. When Monday is started in month that should be considered.

Please help me to get it done in php7.1, This is for magento subscription module. It will rebills the term who the customer subscribed to a plan.

Thank you.

Jdprasad V
  • 11
  • 4
  • Is another way of putting it the first Monday of the month + 2 days? – Jonnix Jul 23 '19 at 18:10
  • No, First week should start with Monday in that wednesday is the billing date, We don't consider the date it not should be 1 or 2 or upto first full week (Monday to Friday). If Monday is 1 or 2 or 3 then It should be the first full week. In an example I mentioned 2. Please check this image, you will get an idea by click this link https://s3.amazonaws.com/tw-inlineimages/435279/0/0/36e61500cf3ab0943a69ddf54f58d73e.png – Jdprasad V Jul 23 '19 at 18:24
  • All of those circled dates are the first Monday of the month, + 2 days.... – Jonnix Jul 23 '19 at 18:31
  • @jonnix could you please elaborate and guide me how can I achieve this by using PHP. – Jdprasad V Jul 24 '19 at 10:21
  • `echo (new DateTime('first Mon of June 2019'))->add(new DateInterval('P2D'))->format('l, d-M-Y');` for example. – Jonnix Jul 24 '19 at 10:52
  • I got your point, I got simple snippet for this echo date('Y-m-d', strtotime('First Monday of this month +2 days')); – Jdprasad V Jul 25 '19 at 10:54

1 Answers1

0

Thanks for your help, finally i found an answer for this question.

here is the code snippet

$firstWednesday = date('Y-m-d', strtotime('First Monday of this month +2 days'));
echo $firstWednesday;

It gives current month first wednesday in first full week of this month.

Result: 2019-07-03 (3rd first wednesday)

Thanks everyone.

Jdprasad V
  • 11
  • 4