A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearWhat's the best way to normalize “time” in PHP? - page 1
User InfoPosts
What's the best way to normalize “time” in PHP?#1
I(m looking for a way to turn user input into normalized data fit for calculation. The input is some length of time, and is coming from Twitter, so it(s string only. Ideally I(d love these results:

an hour and a half --> 01:30

27.52 --> 00:28

5:24 --> 05:24

Is this is a particularly difficult thing to do? I could focus on coaching the users on how to create good input, but also don(t want to be too strict.

Any suggestions would be great,


posted date: 2009-04-07 07:12:00

Re: What's the best way to normalize “time” in PHP?#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-07 07:12:01

Re: What's the best way to normalize “time” in PHP?#3
I think the best you(ll get is the strtotime (http://us3.php.net/strtotime) function.

posted date: 2009-04-07 07:16:00

Re: What's the best way to normalize “time” in PHP?#4
Three things to make it work:regular expressionsfuzzy logic (lots of if/else statements)strtotime to normalize to standard unix epoch time (which makes additions/subtractions very easy)Since it(s user input and non-deterministic that(s the only way. Even then the results won(t be 100% reliable and a small margin of error should be acceptable.

posted date: 2009-04-07 07:30:00

select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.