rajaahsan Posted May 25, 2011 Share Posted May 25, 2011 Hy every one i have this two file code one is index.php and second is insert.php here is index.php code , <html> <body> <form action="insert.php" method="post"> Time <input type="text" name="time" /> <input type="submit" /> </form> <?php $ctime = date('h:i:s A'); echo "Current time is : " . $ctime ; echo "<br>"; $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("time", $con); $result = mysql_query("SELECT * FROM time"); while($row = mysql_fetch_array($result)) { echo $row['time']; echo "<br />"; } mysql_close($con); ?> </body> </html> here is insert.php code , <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("time", $con); $sql="INSERT INTO time (time ) VALUES ('$_POST[time]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; echo "<br>"; echo "<a href='index.php'>Home</a>"; mysql_close($con) ?> This code work fine but when it returns me the ouput in this format Time (inputbox) submit Current time is : 07:25:53 PM 10:55:00 10:55:00 i saved one value with 10:55 AM in my field box and one value with 10:55 PM but no effect what is the problem i want to display the output as like this, 10:55:00 AM 10:55:00 PM Hope you understand what i want... thanks Quote Link to comment https://forums.phpfreaks.com/topic/237436-date-format-problem/ Share on other sites More sharing options...
The Little Guy Posted May 25, 2011 Share Posted May 25, 2011 Try this: while($row = mysql_fetch_array($result)) { echo date('h:i:s A', strtotime($row['time'])); echo "<br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/237436-date-format-problem/#findComment-1220054 Share on other sites More sharing options...
rajaahsan Posted May 25, 2011 Author Share Posted May 25, 2011 thanks it worked but now tell me that i have to put the time like this 17:00 i want to enter time in like this 5:00 PM format as i view 5:00 PM Quote Link to comment https://forums.phpfreaks.com/topic/237436-date-format-problem/#findComment-1220083 Share on other sites More sharing options...
Pikachu2000 Posted May 25, 2011 Share Posted May 25, 2011 When posting code, enclose it within the forum's . . . BBCode tags. Quote Link to comment https://forums.phpfreaks.com/topic/237436-date-format-problem/#findComment-1220091 Share on other sites More sharing options...
The Little Guy Posted May 25, 2011 Share Posted May 25, 2011 thanks it worked but now tell me that i have to put the time like this 17:00 i want to enter time in like this 5:00 PM format as i view 5:00 PM ?? Quote Link to comment https://forums.phpfreaks.com/topic/237436-date-format-problem/#findComment-1220101 Share on other sites More sharing options...
rajaahsan Posted May 25, 2011 Author Share Posted May 25, 2011 i mean to say that , code is working f9 know but , i have to putt the time value in this format in text box 17:00 i want to put 05:00 PM in text box which automatically save my time value in sql like 17:00 Quote Link to comment https://forums.phpfreaks.com/topic/237436-date-format-problem/#findComment-1220111 Share on other sites More sharing options...
fenway Posted May 27, 2011 Share Posted May 27, 2011 That's up to you in PHP. Quote Link to comment https://forums.phpfreaks.com/topic/237436-date-format-problem/#findComment-1221100 Share on other sites More sharing options...
dougjohnson Posted May 27, 2011 Share Posted May 27, 2011 This might help? print( date("H:i:s", strtotime("1:30 pm")) ); output: 13:30:00 print( date("g:i a", strtotime("13:30:30 UTC")) ); output: 8:30 am Quote Link to comment https://forums.phpfreaks.com/topic/237436-date-format-problem/#findComment-1221108 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.