1

I have a php mysql query for a datetime. The result from the query is:

2017-09-04 11:58:26

I use the below and it appears the time is wrong.

$date_time = new DateTime($row['act_date_long']);
$date_time->format('D n/j/Y g:s a')

The result I get is:

Mon 9/4/2017 11:26 am

I need the result to be

Mon 9/4/2017 11:58 pm

What is causing the time difference and how do I format the datetime to my desired format? Thanks!

4
  • 2
    Have you tried to check timezone? Commented Sep 5, 2017 at 6:06
  • 1
    11:00 is AM if you don’t give any more information. You need to either store the time in 24 hour format, or store AM/PM too. Commented Sep 5, 2017 at 6:07
  • 3
    $date_time->format('D n/j/Y g:i a'); it should be i(for minute) instead of s(for second) Commented Sep 5, 2017 at 6:17
  • 1
    Your time 2017-09-04 11:58:26 is in 24hr format. Then how could you make 11:58:26 as PM? If it was 23:58:26 it will be PM Commented Sep 5, 2017 at 6:38

1 Answer 1

2

The format for time is incorrect, your printing g:s which is hours and seconds.

Should be

$date_time->format('D n/j/Y g:i a');
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.