简体   繁体   中英

How to Get First Week Saturday date of current month in php?

how to get Saturday first week date of the current month...Actually I have two input data field first is start date and second date input what I am looking for is first start date is always starts from every week on Saturday and submit report date is always next week Wednesday

First Start Date Input

$date=date('m/d/Y');
<input id="mock_test_date" name="start date" placeholder="" type="text" class="form-control"  
value="date('m/d/Y')" readonly="readonly" />

Second Date Input

<input id="mock_test_date" name="start date" placeholder="" type="text" class="form-control"  value="date('m/d/Y', strtotime($date .' +4 day'))" readonly="readonly" />

how can I get the First Week Saturday on every month and on the second field I will get date of next Wednesday....if first input Saturday is on month end then i will get next month wednesday date

You can simply use DateTimeImmutable to get the next Saturday and the next Wednesday relatively to the already found Saturday:

$saturday = (new DateTimeImmutable)->modify('next Saturday');
$wednesday = $saturday->modify('next Wednesday');

var_dump(
    $saturday->format('D M j G:i:s T Y'),
    $wednesday->format('D M j G:i:s T Y')
);

The result would be:

string(27) "Sat Feb 22 0:00:00 EST 2020"
string(27) "Wed Feb 26 0:00:00 EST 2020"

It is not clear what is being sought. An example would be helpful. The solution with DateTime as I understand the question:

$firstSaturdayThisMonth = date_create('first Saturday of this Month');
$wednesdayAfterFirstSaturday = (clone $firstSaturdayThisMonth)->modify('next Wednesday');

echo $firstSaturdayThisMonth->format('D, j.M')
  ." - ".$wednesdayAfterFirstSaturday->format('D, j.M Y');

The result of today 19.02.2020:

Sat, 1.Feb - Wed, 5.Feb 2020

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM