The time comes to me in this format

$time='16:00:00/23:00:00';

You need to separately get 16:00:00 and separately, then what after the slash 23:00:00

Googled how to get the second part:

 date_format(date_create_from_format('H:i:s/H:i:s',$time),'H:i:s'); 

Displays 23:00:00 . But how to get the first one? Thank.

  • 2
    Not easier explode('/', $time); and process the array with the clock? - user207618
  • @Other, not easier. This is a crutch then - Roman Kozin
  • one
    @RomanKozin, in a sense? This time to pass is a crutch. And if you need a period - explode for this and created. - user207618
  • @Other, I'm still sleepy) Sorry) Not so perceived brains - Roman Kozin
  • In this format, the time period is transmitted by the Google service api.ai, if Google already transmits data as a crutch, then what about others ?. Ok I will try to use explode. Thank. - Alex Sokolov

1 answer 1

 date('dm-Y',strtotime($_my_time)); 

strtotime converts your time into an object to work with time and after, you can already manipulate it through the date function.

In your case:

 $time = explode('/', $time); /** или **/ preg_match_all('~([0-9]{2}:[0-9]{2}:[0-9]{2})~', $time, $results); var_dump($time); var_dump($results); 

Regular Expression Results

  • strtotime returns a joyful false and there is nothing to var_dump(date('dmY', strtotime('16:00:00/23:00:00'))); // string(10) "01-01-1970" from there: var_dump(date('dmY', strtotime('16:00:00/23:00:00'))); // string(10) "01-01-1970" var_dump(date('dmY', strtotime('16:00:00/23:00:00'))); // string(10) "01-01-1970" . As expected. - user207618
  • @Other, soryan :) I haven't woken up yet) - Roman Kozin