From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert number to date and time

Hi I use the following code to convert timestamp to number and then convert it back to string but it doesn't work.

For example if teh current time is 12:52:30 the number will be 125230 but the the resulting string is   024710 ..  Could you please let me know what is wrong here

Thanks

 

hj.png

0 Kudos
Message 1 of 3
(3,097 Views)

Well, the format of your number has no numerical relationship to the time.

 

This is the format that it appears that you want:

 

hour*10000 + minute*100 + second

 

To get that format you must implement that algorithm. There might be a simpler way but this will work:

 

TS to string.png

 

Note that the Format Date/Time String function will use the current time if nothing is wired to the timestamp input.

 

To convert a number in that format to a string you must implement the reverse process of splitting the number into separate values for hours, minutes, and seconds. Then each must be converted to a string. The individual strings can be concatenated to form a single string.

 

number to TS string.png

Lynn

0 Kudos
Message 2 of 3
(3,078 Views)

Seems like you're doing something funny, probably because you are using inappropriate functions for conversion.  I have attached a couple of options of what I think you might be trying to do.

 

 

time.png

0 Kudos
Message 3 of 3
(3,061 Views)