0

After more than an hour struggling and trying I'd like to ask it here.

Trying to make something with weeks etc. in php I got from you site this: Get all Work Days in a Week for a given date

Nice and will work for me fine.

But ... I can't get, trying and trying, the data out of this part: [date] => 2013-08-12 00:00:00

Array
(
    [0] => DateTime Object
        (
            [date] => 2013-08-12 00:00:00
            [timezone_type] => 3
            [timezone] => Europe/Amsterdam
        )

How to get that date out of the array ? Please help me out, thanks in advance for the help !

Community
  • 1
  • 1
Jeroen
  • 1

2 Answers2

0

Use DateTime::format()

$dateTime = new DateTime('2013-08-12 00:00:00');
echo $datetime->format('Y-m-d'); // produces 2013-08-12
John Conde
  • 217,595
  • 99
  • 455
  • 496
0
$firstMondayThisWeek= new DateTime('2013-08-12');
$firstMondayThisWeek->modify('tomorrow');
$firstMondayThisWeek->modify('last Monday');

$nextFiveWeekDays = new DatePeriod(
    $firstMondayThisWeek,
    DateInterval::createFromDateString('+1 weekdays'),
    4
);

$dateTimes = iterator_to_array($nextFiveWeekDays);
foreach ($dateTimes as $dateTime) {
    echo $dateTime->format('Y-m-d H:i:s');
}
user1855153
  • 579
  • 4
  • 15