3

What i'm trying to do here is to get dates with specific criteria from 3 months range, and put them into arrays.

to get dates:

$begin = new DateTime( 'NOW' );
$end = new DateTime('NOW');
$end->modify('+6 month');

$interval = new DateInterval('P1D');
$period = new DatePeriod($begin, $interval ,$end);

filters to get my dates of criteria:

foreach ( $period as $dt ){
    if ((!($dt->format("l") === 'Saturday') || ($dt->format("l") === 'Sunday')) && ($dt->format("d") == '14')){
        $meeting = $dt->format( "Y-m-d" );
        echo $dt->format( "Y-m-d" ) . '<br />';

    }

    if((($dt->format("l") === 'Saturday') || ($dt->format("l") === 'Sunday')) && ($dt->format("d") == '14')){
        $dt->modify('Next monday');
        echo $dt->format( "Y-m-d" ) . '<br />';

    }   
}

echo '<hr>';
$interval_2 = new DateInterval('P1M');
$period_2 = new DatePeriod($begin, $interval_2 ,$end);

foreach ( $period_2 as $dt ){
    $dt->modify('last day of this month');  
    //echo $dt->format( "l Y-m-d\n" ) . '<br />';
    if(($dt->format("l") === 'Saturday') || ($dt->format("l") === 'Sunday') || ($dt->format("l") === 'Friday')){
        $dt->modify('previous Thursday');
        echo $dt->format( "Y-m-d" ) . '<br />';
    } else {
        echo $dt->format( "Y-m-d" ) . '<br />';
    }


}

well all this works perfect, but they are just displaying, and i want to put them in array to get them into CSV file with fputcsv so i need them like:

Month, first_date, second_date

how can i achieve that?

1 Answer 1

1

resolved my issue by declaring:

$meet = array();
$test = array();

and after that in each if:

$meet[] = $dt->format( "Y-m-d" );
$test[] = $dt->format( "Y-m-d" );

and this way if you make a var_dump, it will have an array for each one of them.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.