•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,521 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,809 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 669 | Replies: 4
![]() |
Hey, this is kind of a dumb problem, but I'm stumped by it. I wrote a little script to track my morning bike rides, and I have a time field to put in the time that I rode. Mind you, this is not the time of the day that I rode, but rather the number of minutes and seconds that my ride lasted.
But with my MySql back end, the only form I could think of was the "time" format, which forces it to HH:MM:SS. My rides rarely last longer than 45 minutes, so I just want to be able to enter the time in the field as MM:SS. Currently I'm just putting it in as "varchar". But eventually I would like to take the information in here and use it to make some graphs and I figure that would be easier if it was a in a time format.
Any idea how?
And lets say that some time in the future, I do ride for over an hour. Is there a way to make it so that I can enter it as MM:SS if it's under an hour, but have the option of entering HH:MM:SS if my ride is longer than an hour?
But with my MySql back end, the only form I could think of was the "time" format, which forces it to HH:MM:SS. My rides rarely last longer than 45 minutes, so I just want to be able to enter the time in the field as MM:SS. Currently I'm just putting it in as "varchar". But eventually I would like to take the information in here and use it to make some graphs and I figure that would be easier if it was a in a time format.
Any idea how?
And lets say that some time in the future, I do ride for over an hour. Is there a way to make it so that I can enter it as MM:SS if it's under an hour, but have the option of entering HH:MM:SS if my ride is longer than an hour?
Last edited by nathanpacker : Oct 4th, 2007 at 12:06 pm.
•
•
Join Date: Apr 2005
Location: New York state
Posts: 487
Reputation:
Rep Power: 5
Solved Threads: 73
When you output the time use date_parse which breaks the time up into an associative array so you can display it in any way you would like but it is still stored the same in the database.
Quick note: even if you only enter MM:SS the database will add 00 to the hour so 45 minutes 5 seconds would become 00:45:05
Example:
Quick note: even if you only enter MM:SS the database will add 00 to the hour so 45 minutes 5 seconds would become 00:45:05
Example:
php Syntax (Toggle Plain Text)
$timeQuery = "SELECT time FROM rides"; $timeResult = mysql_fetch_row($timeQuery); $parsedTime = date_parse($timeResult['time']); echo $parsedDate['hour']." hour(s), ".$parsedDate['minute']." minute(s), and ".$parsedDate['second']." second(s).";
Last edited by ShawnCplus : Oct 4th, 2007 at 5:48 pm.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h-->++ r z+*
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h-->++ r z+*
•
•
Join Date: Apr 2005
Location: New York state
Posts: 487
Reputation:
Rep Power: 5
Solved Threads: 73
Another way to do it would have three separate text boxes for hours, minutes and seconds respectively then when you actually submit it you can concatenate the three and make any empty boxes 00.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h-->++ r z+*
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h-->++ r z+*
•
•
Join Date: Jul 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
Though you say you never ride more than one hour, you should handle the case anyway.
First fill the minutes with your ride's duration, possibly overriding 60. Then split this value into hour(s) and remaining minutes. Then concatenate with seconds, and insert the result into database.
(Note that IMHO, it is not a good idea to name a database column as 'time' since it is a column type keyword - though MySQL manual says it is allowed as unquoted identifiers for compatibility reasons)
First fill the minutes with your ride's duration, possibly overriding 60. Then split this value into hour(s) and remaining minutes. Then concatenate with seconds, and insert the result into database.
php Syntax (Toggle Plain Text)
$ride_minutes_total = <some integer value>; $ride_hours = (int)($ride_minutes_total/60); $ride_minutes = ($ride_minutes_total % 60); // Using modulo operator to get remaining minutes $ride_seconds = <some integer value>; $ride_id = <some id>; $ride_duration = sprintf('%02d:%02d:%02d', $ride_hour, $ride_minutes, $ride_seconds); $timeInsertQuery = "insert INTO rides SET id ='$ride_id', duration='$ride_duration' "; $result = mysql_query($timeInsertQuery) or die("Query failed");
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- setting up an automatic email reply from a form. (Site Layout and Usability)
- Displaying time on a Form (VB.NET)
- impose a limitation on form of time duration (PHP)
- Need help to encrypt and decrypt password in VB (Visual Basic 4 / 5 / 6)
- Automatic email reply to Form (Site Layout and Usability)
- Code run when form shown ? (C#)
- To form a palindrome of a given string (C)
- I need help with this c++ program please!!! (C++)
Other Threads in the PHP Forum
- Previous Thread: help me with my dropdowns...
- Next Thread: php email


Linear Mode