LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert Date/Time String to Timestamp

Solved!
Go to solution

This should be dead simple.  

 

Date/Time String:   3/9/2023 5:51:23 PM  

 

Convert to Timestamp. 

 

Why is this so complicated? 

---------------------
Patrick Allen: FunctionalityUnlimited.ca
0 Kudos
Message 1 of 3
(848 Views)
Solution
Accepted by topic author pallen

Because date and time is a very difficult topic to handle correctly!

 

However the principal problem is not that hard. You can use for your case Scan from String with a format string of

%<%m/%d/%Y %I:%M:%S %p>T

 

The real problem starts if this is not your local time zone but something else.

 

For a UTC timestamp you could change it to

%^<%m/%d/%Y %I:%M:%S %p>T

 

Other timezone handling is tricky. And you may also have to check if your date is really MM/DD/YYYY. It usually is if you use slashes as separator but it does not have to be.

Rolf Kalbermatter
My Blog
Message 2 of 3
(845 Views)

I'd been struggling with the Scan from String examples and just figured it out.  

 

You posted the same solution I came to.   Thanks for quick reply! 

---------------------
Patrick Allen: FunctionalityUnlimited.ca
0 Kudos
Message 3 of 3
(838 Views)