Jump to content

String>Time Conversion


Recommended Posts

QUOTE(yen @ May 15 2005, 07:40 AM)

Often people read text data which includes a date\time.

Currently, there is no inherent function in LV for converting a time string to a timestamp.

The suggestion is to have a VI, basically a reverse VI to Format Date\Time String, which will convert a date\time string to a LV timestamp based on a LV format string.

I was having the same wish for a function when I decided to do this for myself...that is convert a string to a LV Timestamp. What I did was prep the string data using the string commands so that it appears in the mm/dd/yyyy format. Create a timestamp control then create a property node for the NumText.Text (Property Node > Numeric Text > Text) and wire the date string to the node. Now when you pass the value from the control it will be formatted as a timestamp.

I hope this helps

Link to comment

The problem with that method is that you're relying on a control and on workarounds.

A better approach is to convert the various string elements to numbers, build them into a time rec cluster and convert that cluster to a timestamp, so that you preserve data flow. There have been some implementations for this posted to the web.

With the addition mentioned here of using Scan From String, it should probably be simpler.

Link to comment
  • 2 months later...

I didn't say the cluster method is simpler. I said the Scan From String method is simpler.

To embed a picture, you need to upload it (there's an attachments section under the post window) and in the Manage Current Attachments ring you can select to embed it in the post.

Link to comment

"Bluetin your solution relies on the fact that your computer time settings don't change.

Yen's as well but are a little bit more error proof."

How do you figure that?!

I am getting a date time STRING as data from any source in this case a datalogger.

When I put the string into a timestamp I can easily subtract 2 timestamps to get the time elapsed.

The point was how to put a string into a timestamp.

Parsing a string into a cluster and then converting the cluster to a timestamp also works as Yen has said.

But he blew off Brokenwire's suggestion as not simple when it is vastly simpler.

QUOTE(yen @ Aug 9 2007, 04:29 PM)

Thanks for the hint on pictures.

The scan Time from string method is great if you have version 8.X

The property node method works in 7.X

It probably also works in 6.X but I don't have any old version 6's

and I don't really want to get out my old version 5.1 just to see.

QUOTE(BrokenWire @ May 21 2007, 11:05 AM)

I was having the same wish for a function when I decided to do this for myself...that is convert a string to a
LV
Timestamp. What I did was prep the string data using the string commands so that it appears in the mm/dd/yyyy format. Create a timestamp control then create a property node for the NumText.Text (Property Node > Numeric Text > Text) and wire the date string to the node. Now when you pass the value from the control it will be formatted as a timestamp.

I hope this helps

By the way BrokenWire you don't need to reformat the string, you need to change the settings of the TimeStamp to match the string.

http://forums.lavag.org/index.php?act=attach&type=post&id=6606 http://forums.lavag.org/index.php?act=attach&type=post&id=6604 http://forums.lavag.org/index.php?act=attach&type=post&id=6605

Link to comment

Ton, I agree that this should not rely on the PC's settings. Since you're reading a time string, you should already know how that string is formatted and use the specific format string.

Bluetin, I said that the Scan from String method is simpler than the cluster method (a basic example of which is shown here), not the control method. It's not any simpler than the control method, since it's basically the same, but I don't like the control method because you have to rely on a control and you probably have to change the control's format to get it to work properly in every case. It works, but seems like a dirty hack. I use LV 7.0 myself, so I don't have the Scan from String either, but I would prefer a proper VI for this over the control method.

Link to comment

QUOTE(yen @ Aug 10 2007, 05:33 PM)

Ton, I agree that this should not rely on the PC's settings. Since you're reading a time string, you should already know how that string is formatted and use the specific format string.

Bluetin, I said that the Scan from String method is simpler than the cluster method (a basic example of which is shown http://forums.ni.com/ni/board/message?board.id=170&message.id=174014#M174014' target="_blank">here), not the control method. It's not any simpler than the control method, since it's basically the same, but I don't like the control method because you have to rely on a control and you probably have to change the control's format to get it to work properly in every case. It works, but seems like a dirty hack. I use LV 7.0 myself, so I don't have the Scan from String either, but I would prefer a proper VI for this over the control method.

As would I, for the same reason

Link to comment
  • 3 weeks later...

Hi,

i have some time scanning / timezone conversion VI's available on my site. They still use LV6 style DBL's so are not really up to date, but they worked splendidly there. I have a temporary version laying around here that has the big TS's and is probably OK but I have not had time to release it. If anyone wants to try that TS version let me know.

http://robijn.net/labview/

Joris

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.

Guest
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.