0

I have an array containing value of full date & time:

Array
(
 [0] => Array
      (
        [name] => Jammy
        [date] => 2012-12-12 09:47:07
        [id] => 151
      )

[1] => Array
    (
        [name] => Kathy
        [date] => 2012-12-11 09:48:43
        [id] => 152

    )

so if i want print like below what should i do ? sample output:

Jammy joined on [ Date: 12 Dec 2012 , Time: 09:48 ]

1

2 Answers 2

5
foreach ($arr as $value) {
   echo $value['name'].' joined on [ Date: '.date('d M Y',strtotime($value['date'])).' , Time:'.date('H:i',strtotime($value['date']));
}
Sign up to request clarification or add additional context in comments.

1 Comment

@BhavinRana thanks to correcting me but i was editing my answer
2

Try this

foreach ($array as $value) {
    $time = new DateTime($value['date']);
    $date = $time->format('d M Y');
    $time = $time->format('H:i');

    echo $value['name'].' joined on [ Date: '.$date.' , Time:'.$time;
}

For more information go to this link: The DateTime class

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.