0

I want to convert MySQL Time data type using PHP and Javascript. I know it can be done using FORMAT_TIME of MySql, but I would like to do the same with php. The Time format is hh:mm:ss by default and I would like to convert it to hh:mm.

3
  • 1
    php.net/manual/en/function.date-create-from-format.php Commented Apr 10, 2012 at 16:39
  • Do You use a Datetime Field? or only Date? or a Timestamp? Commented Apr 10, 2012 at 16:39
  • Where does the javascript fit in? Commented Apr 10, 2012 at 16:41

3 Answers 3

1

Just feed the date into the following function(s):

<?php echo date("h:i", strtotime($date)); ?>
Sign up to request clarification or add additional context in comments.

1 Comment

thanks, I like this solution! Can be integrated easily where I display the output
1
//any date is ok, we care only about the hours and minutes
// $your_date is what comes from db in format hh:mm:ss
$date = new DateTime('2000-01-01 '.$your_date);
echo $date->format('H:i');

Comments

0

I think you could create a DateTime object and then use format("h:i") to get the desired output

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.