|There's more than one way to do things|
Re^3: Time matching YYYY-MM-DD HH:MM:SS.SSSby dave_the_m (Parson)
|on Jul 26, 2012 at 19:03 UTC||Need Help??|
Well, I asked for code and data that demonstrates the inconsistency; you didn't show any data.
Having said that, your code is ... well .. just God-awful.
It violates just about every rule of good coding practice and style going. I haven't the will to go though a complete list (maybe some other kind soul will have the patience), but just for starters:
at the start of your code. You will be amazed!
The two-arg form of open is frowned upon. The one-arg form is vomit inducing.
In your second branch, you have $i = $i++; which is definitely not what you need, and may in fact be the cause of all your issues.