Jump to content

Time Date String convert to time stamp

Recommended Posts


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.

Thanks for any help you can provide :worship:


Link to comment

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:

  • Like 1
Link to comment

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"?


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!


Link to comment
  • 8 years later...

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.

Link to comment

Join the conversation

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

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

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

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.