09-18-2013 07:23 PM
Hong.Zhang@agresearch.co. wrote:
Why error?
Thanks
Your code is fine for times in the morning (AM), but fails for times in the afternoon because the Scan from String expects to see either "am" or "pm" but you're feeding it "am" or "p.m." and the extra dots for the PM times cause the error. The code I uploaded in the previous post fixes both am and pm, by removing the dots from ".m.".
09-18-2013 07:42 PM
There are two errors. The format specification should be "%<%d/%m/%Y %I:%M:%S %p>T" Note the change from H to I and the replacement of X with p.
The other is the Search and Replace String function needs to replace "a.m." with "AM" and "p.m." with "PM". Your code only does one replacement and it uses lower case.
Lynn
09-18-2013 10:43 PM
Hi nathand
your codes is working. Date order is right but time is not right. For example, one row is 10/07/2012 3:00:00 a.m. next row is 10/07/2012 3:00:00 p.m. I want one row is 10/07/2012 3:00:00 a.m. next row is 10/07/2012 4:00:00 a.m.
How to is?
Hi Lynn
Thank you very much for help.
I could make ypur code to work. There is error. Please have a look at my vi.
Thanks
09-18-2013 11:26 PM
Why do you have two different For Loops, and you aren't using one of them.
When I use your upper For Loop, and disable the lower one, your the code seems to work fine.
09-18-2013 11:42 PM
Thanks RavensFan
The two For Loops are for two ideas. I only need one of them.
The lower one is working. But time order is not right.
The upper one report error at Scan From String function.
Thanks
09-19-2013 12:35 AM
The lower one won't work because you need to use I for the hour code rather than H (as was pointed out in earlier messages. (Read the help for the format string codes to find out why.) Also, it won't work because you are replacing m with M The earlier examples showed .m. being replaced with m. You forgot the periods. And you are converting it to an upper case M. So you wind up with a scan from string error because it doesn't know how to decode a.M. or p.M.
The upper loop works just fine. I don't understand why you are saying the upper loop is causing you an error. (Are you getting the words "upper" and "lower" mixed up?)
In short,
Attached is your VI with the loop that works. I saved the results as the defaults in the indicator to show you the order is just fine.
09-19-2013 03:53 AM
Thanks RavensFan
Your results looks prefect. But when I run it still got error. Please see the attached error message. What is problems?
The original data came from a database wrote by third part. I could not change it. I only can read the data out.
Thanks again.
Hong
09-19-2013 08:38 AM - edited 09-19-2013 08:40 AM
If the "result looks perfect", how can you "still get an error"?
Put a probe on the string wire going into the Scan from String, or at least an indicator That way we can see what line it is hanging up on when it stops. Then post a screenshot of that.
Is it any chance that you are using an operating system where it uses a comma for a decimal point, instead of a period? While I don't see that having an effect in the format string you have, that is a typical problem with format strings when one person has a format string that works fine, but it fails for another person. However, your timestamp constant there appears that your OS is using a decimal point.
Until we see exactly what string it is hanging up on, there is no way to know what is going wrong.
09-19-2013 10:23 AM
@johnsold wrote:
There are two errors. The format specification should be "%<%d/%m/%Y %I:%M:%S %p>T" Note the change from H to I and the replacement of X with p.
The other is the Search and Replace String function needs to replace "a.m." with "AM" and "p.m." with "PM". Your code only does one replacement and it uses lower case.
Oops! Thanks, Lynn, for noting the errors in the format string. I never remember the format specifiers and apparently scanned the help too quickly when putting together this example.
A quick check indicates that the %p specifier is not case sensitive, so it's fine to replace ".m." with "m" as I showed without converting to uppercase.
09-19-2013 10:42 AM
nathand,
I noticed that after removing the .m. it was less particular. The help file only shows upper case AM and PM. Sounds like a situation where the documentation is less than complete or accurate. There are so many combinations in time formats that a few errors in the documentation or performance may exist.
Lynn