LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert Date/Time in String format to Timestamp format

Hi ,
 
I am getting data from Citadel Database using Write trace to Spreadsheet.vi ( in DSC pallete).
But it is giving the date/Time in the string format,i need to show the date/Time along with some data in XY graph .But the XY graph  takes time as TimeStamp. I am attaching the vi's which convert the string to timestamp , but when string input is 3/29/2008 12:00:07 PM it gives timestamp as 12:00:07 AM 3/30/2008 . It gives AM instead of PM.
 
Please look for the index 480 in the saved timestamp string array on the FP of trial.vi.
 
 
regards
Santosh Kumar
Download All
0 Kudos
Message 1 of 11
(16,148 Views)
The Date/Time to Seconds function is operating correctly. The problem is that you're feeding in an hour of -2 since you're subtracting 12 from the hour if it's AM. So, that means it's moving it to be 2 hours before midnight, hence, 10 PM. In your case statement you should not be doing anything for the "AM" part.


Message Edited by smercurio_fc on 04-03-2008 10:26 AM
0 Kudos
Message 2 of 11
(16,127 Views)

It is executing wrongly. Please check at the index 480. Whatever he has stated is true.

The timestamp that has to come as AM, comes as PM only. This happens even after doing nothing in the AM case.

Can somebody confirm this behaviour or suggest a workaround?

- Partha ( CLD until Oct 2027 🙂 )
0 Kudos
Message 3 of 11
(16,108 Views)
Hi smercurio_fc,
 
Please try the following.
 
Just open the Convert_String_to_TimeStamp.vi he has attached. Change its properties to normal priority & allow debugging in Execution.
Copy the value displayed on its FP free label into the control & run the VI. The expected answer is to be in AM, but it shows it in PM.
 
Moreover, I ve one more query.
 
Why does a timestamp indicator shows time in PM instead of AM, when placed for the forst time on the FP?
Please see the attached image.
- Partha ( CLD until Oct 2027 🙂 )
0 Kudos
Message 4 of 11
(16,107 Views)
If you re-read my statement I said that the Date/Time To Seconds function is executing correctly. This statement is still true. I wasn't referring to his VI that parses the string. The Date/Time To Seconds function uses military time. It has no AM/PM input, so if you're trying to parse a string that has that text in it, then you need to specify the hours correctly. 12 AM should be entered as 0 hours. 1 AM should be entered as 1 hour. 12 PM should be entered as 12. Etc. The parsing VI was blindly taking anything with AM and subtracting 12. Well, 10 AM became -2, which Date/Time To Seconds interpreted (correctly) as the previous day.
0 Kudos
Message 5 of 11
(16,069 Views)
You are correct. Change the AM case to this (see attached)
0 Kudos
Message 6 of 11
(16,053 Views)

I'm on 8.2 so can't read the vi's, but from the comments it seems that there's an attempt to parse the time string, them pass it to time/date to seconds.

How about simply using 'scan from string', with "%<%m/%d/%Y %I:%M:%S %p>T" as the format string.  The output is a time stamp. NI have already written the parsers for you!

Rod.

Message 7 of 11
(16,048 Views)
The user is actually already using Scan From String, but you have a very good point, and that's an excellent and clean solution.


Message Edited by smercurio_fc on 04-04-2008 01:04 PM
0 Kudos
Message 8 of 11
(16,032 Views)


Rod wrote:

How about simply using 'scan from string', with "%<%m/%d/%Y %I:%M:%S %p>T" as the format string.  The output is a time stamp. NI have already written the parsers for you!

 

Excellent answer! Problem solved. Smiley Happy

BTW, can you explain me what are those format specifiers %I & %p stand for? I cannot see them in the LV help.

- Partha ( CLD until Oct 2027 🙂 )
0 Kudos
Message 9 of 11
(15,994 Views)
I see them listed here.

<%p> AM or PM flag

<%I> hour (12-hour clock) (01–12)
(it's a capital i)

Ton
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Message 10 of 11
(15,987 Views)