LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert date/time string to numeric indicator

Solved!
Go to solution

I'm trying to convert a string that is just a date (ie 7/10/2017), and for whatever reason the day and year will be correct, but the month is always 12 (ie 12/10/2017).


Can someone guide me with this problem?

0 Kudos
Message 1 of 10
(8,663 Views)
Solution
Accepted by topic author TMIET

So the string should be Month/Day/Year?  Then you should be explicit.  Otherwise the format will use the system format.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 10
(8,651 Views)

Thanks! It is exactly that!

0 Kudos
Message 3 of 10
(8,638 Views)

Hello!

 

I am trying to convert date string to number, to feed as the X values in a XY Graph, but I only have access to Labview 7.1. I cannot find this conversion button (which is shown in the answer to this problem) anywhere. Can someone please let me know if it is available in Labview 7.1? If this is not available, is there any simple way to do this? 

 

Thank you very much in advance.

 

 

0 Kudos
Message 4 of 10
(6,736 Views)

Hi gracabrotas,

 

I'm sure LabVIEW7.1 already knows about the ScanFromString function…

 


@gracabrotas wrote:

If this is not available, is there any simple way to do this? 


You can always switch back to parse your string "manually" by splitting it into substrings and use the StringToNum conversion functions on day/month/year substrings. But again: LV7.1 surely knows the ScanFromString function…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 10
(6,733 Views)

@GerdW wrote:

Hi gracabrotas,

 

I'm sure LabVIEW7.1 already knows about the ScanFromString function…

 


@gracabrotas wrote:

If this is not available, is there any simple way to do this? 


You can always switch back to parse your string "manually" by splitting it into substrings and use the StringToNum conversion functions on day/month/year substrings. But again: LV7.1 surely knows the ScanFromString function…


It seems to me there was at least one caveat about scan from string with timestamps in LV 7.1 but I cannot remember what it was...

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 10
(6,718 Views)

@GerdW wrote:

 

I'm sure LabVIEW7.1 already knows about the ScanFromString function…

LV 7.0 definitely didn't support the %<>T code needed to parse a timestamp and I'm fairly sure 7.1 didn't either. I think it was added in 8.0.

 

As you said, the practical solution is to break it into parts and then build it back up. Assuming the string is in a fixed format, then it's fairly easy to parse it in fixed way. In any case, the date time rec cluster is your friend, as you can use that directly with the parts of your string and then convert it to a timestamp using the built in function (which I'm fairly sure should be there in 7.x).


___________________
Try to take over the world!
0 Kudos
Message 7 of 10
(6,692 Views)

@GerdW wrote:

Hi gracabrotas,

 

I'm sure LabVIEW7.1 already knows about the ScanFromString function…



Yes it does, but that function does not know about the %<>T format specifier as explained by Yair. Neither does Format into String.

 

The Scan From String can still be used but you need to scan the parts separately and convert them accordingly using the Data/Time to Seconds node. However, extra care needs to be taken as the Timestamp is in fact a "yes indeed" timestamp and therefore uses timezones. And a date only timestamp happens to be exactly on the brink between two dates, so if you are not careful about it and transfer a binary timestamp between two computers with different timezone settings, your timestamp as a date is suddenly a day off.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 8 of 10
(6,677 Views)

Hello everyone!

 

Indeed 7.1 did not accept the %< >T code, and I had to change tactics. It took me a while to get the right result, but by using elapsed time I could do what I needed.

I know this is not the best coding technique, but I am a chemist, and I don't know much programming. For now, as long as it works, I'm happy 🙂

I found labview really helpful, and I will try to learn it better to improve my skills. I am still struggling especially with arrays and clusters, but I will get there!!

 

Here is the final version of the program I made. Again, I know it's not pretty, but it works.

Thanks to everyone who helped me!!

 

gracabrotas_0-1621519446248.png

 

0 Kudos
Message 9 of 10
(6,638 Views)

I try to do something very similar, but with an hour/minute/seconds timestamp you see below. Checking the context help the %p specifier should catch the AM/PM flag, but the cluster output always has 9 for an hour. For PM it should be 21.

 

What do I miss here?

thx!

 

1984_0-1655722378136.png

 

 

UPDATE: nevermind... in this case %I should be used instead of %H

0 Kudos
Message 10 of 10
(5,657 Views)