# Time Date String convert to time stamp

## Recommended Posts

Hi,

I was wondering if anyone knows of a way in which one can convert a time and date string that is read from a .txt file, into a time stamp value.

The reason I ask this is because I need to calculate the time between cycles on a certain machine. (ie - subtract cycle ON time with the previous cycle OFF time)

Currently, we have a program that spits out the data onto a .txt file in the following format.

11:32:28 AM 06/03/04CYCLEOFF

11:40:24 AM 06/03/04CYCLEON

11:45:26 AM 06/03/04CYCLEOFF

11:47:52 AM 06/03/04CYCLEON

and so on...

the main concern however is that there might be confusion in the calculation when the time switches to that of the next day.

ie -

11:32:28 PM 06/03/04CYCLEOFF

11:40:24 PM 06/03/04CYCLEON

11:45:26 PM 06/03/04CYCLEOFF

12:47:52 AM 06/04/04CYCLEON

01:10:10 AM 06/04/04CYCLEOFF <-- converting this time to seconds would cause an error in subtraction

I am thinking that the best way to approach this problem is to convert the string into a time stamp of the number of seconds from 12:00 am., Friday, January 1, 1904, Universal time. Then it'll just be simple arithmetic However, I have not figured out a way of doing this conversion. Is there a function that I am not aware of?

If anyone can figure out a better, more efficient way of solving this problem, I more than welcome the criticism and suggestions.

Sorry for the long post!

Hopefully the question is clear.

Naruto

To easily convert the time string to a time stamp, create a time stamp control with the same formatting as the time string. Then wire the time string value to the property Numeric Text>Text of the time stamp. It is like copying the string into the control. LabVIEW convert the value automatically. :thumbup:

Thanks for the prompt reply jpdrolet.

I am still quite new to labview, so I was not sure how to create the time stamp control. Now that I have figured that out, how do I actually go about formatting the control though?

is there a way of setting the years to just 2 numbers (ie - 04) as opposed to 4 (ie - 2004)?

I also need to account for AM and PM values, can that be formatted?

will labview recognize the AM or PM string and convert the time accordingly?

for the second part of your post, u say to wire the time string value to the property numeric text>text on the time stamp

which function would this be called? would that be "Get Date/Time String"?

so

1) wire the time stamp that i format from the string i want (ie - 00:00:00 PM MM/DD/YY)

2) to the "Get Date/Time String"

3) Set want seconds to true,

4) and wire an indicator to the time string output?

if this is correct, then i just need to know how to format the time stamp properly.

Any help on this would be greatly appreciated!

Thanks!

PERFECTO!!!

Thank You very much guys!

• 8 years later...

This is 8 years old, but still a very useful hint !!!

Many thanks!

I believe this is what jpdrolet had in mind:

This one is really Nice.

Refreshing the Knowledge

Thanks

So using a TimeStamp indicator instead of scan from string. I'm not sure if that is the intended use of a control.

I would not rely on this trick/hack/gem.

And I don't really see the need for that.

Ton

And I don't really see the need for that.

These days, no, but back in 2004 Scan From String didn't know how to parse a time string into a time stamp. I believe that was added in 8.0.

And just to clarify Ton's point - you can input the same format string into a Scan From String function and get out a time stamp.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×