0

Hello I'd doing a project which is related to android , php and mysql, there is this function that i need to get the user input from android device, and post it to php script which then query the database, one of the inputs is a time string the format is "XX:XX:XX" , this string will be stored as a time in mysql, my question is how do I convert the string into mysql time format in php ? (only time, NO DATE)

1
  • mysql time store in "HH:MM:SS" and what you are getting is same. So you can directly save in the table. Commented Oct 23, 2013 at 11:45

3 Answers 3

2

according to http://dev.mysql.com/doc/refman/5.0/en/time.html, the TIME type should accept strings formatted like 'HH:MM:SS' so you should be able to directly save your data without the need to convert anything.

Sign up to request clarification or add additional context in comments.

Comments

0

Unix time or full date format ? for unix time do :

<?php
$time=strtotime($input);
?>

and full-date format :

<?php
$time=date('c',strtotime($input));
?>

any else ?, good luck

Comments

0

To convert the date in a mysql Timestamp format you can use the following snippet :

$mysqlTime = date("H:i:s", strtotime("20:30:10"));

the variable $mysqlTime will hold it for you.

I think I clearly understood your question.

3 Comments

He mention that "only time, NO DATE" and you are giving him date also.
Thank you ! But it didn't work, when I do the insert, and checked myphpadmin it shows 00:00:00, and I already post that I do not want date at the beginning I'm storing time only
Please paste me the column format that your mysql DB Uses . It's DATE , DATETIME or TIMESTAMP ?

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.