-3

I have 2 datetime value:

$begin = new DateTime( "2015-07-03 12:00:00" );
$end   = new DateTime( "2015-07-04 14:00:00" );

and I need to split it to this result:

val11 = 2015-07-03 12:00:00;
val12 = 2015-07-03 23:59:59;

val21 = 2015-07-04 00:00:00;
val22 = 2015-07-04 14:00:00;
Cœur
  • 37,241
  • 25
  • 195
  • 267

3 Answers3

1

Hi did you have read the manual ? http://php.net/manual/fr/class.datetime.php

$val11 = $begin->format('Y-m-d H:i:s');
$val12 = $begin->format('Y-m-d').' 23:59:59';

With that you should be able to code the complete answer.

pietro
  • 902
  • 10
  • 22
0

Use DateTime.add(DateInterval)

DateInterval {
/* Properties */
public integer $y ;
public integer $m ;
public integer $d ;
public integer $h ;
public integer $i ;
public integer $s ;
public integer $invert ;
public mixed $days ;
/* Methods */
public __construct ( string $interval_spec )
public static DateInterval createFromDateString ( string $time )
public string format ( string $format )
}

So, you need to add 3 DateInterval's; 7 hours 59 minutes 59 seconds.. then add another second - and lastly 14 hours. Or whatever your logic is, make some math from the hour / minute / second of the DateTime and adjust your DateInterval accordingly. Each time you add an interval, you print a formatted datetime string.

mschr
  • 8,531
  • 3
  • 21
  • 35
0

Values $begin and $end are datetime from form ($POST). I want to show "inputs" and "outputs" with real data.