LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there any easy way to get Seconds from a Date/Time string?

Solved!
Go to solution

I have 2 strings of the following format that I would like to convert to seconds (since 1900). I need this value to set the t0 on a plot.

 

Date: "06-30-2014"

Time: "16:06"08"

 

Is there a CVI function that will do this conversion for me? If not, is there an easy way to do it?

 

Thanks!

0 Kudos
Message 1 of 3
(4,443 Views)
Solution
Accepted by topic author Hoof

This code should do what you want:

 

#include <formatio.h>
#include <ansi_c.h> static time_t calt; static struct tm tm; static char msg[64]; static int yy, mm, dd, hh, mn, ss; strcpy (msg, "06-30-2014 16:06:08");

// Extract component from date/time string Scan (msg, "%d[x]%d[x]%d[x]%d[x]%d[x]%d", &mm, &dd, &yy, &hh, &mn, &ss);

// Transfer components to a tm struct tm.tm_hour = hh; tm.tm_min = mn; tm.tm_sec = ss; tm.tm_year = yy - 1900; tm.tm_mon = mm - 1; tm.tm_mday = dd;

// Obrtain the calendar time calt = 0; calt = mktime (&tm);

 

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 3
(4,435 Views)

Thanks for the help with this.

0 Kudos
Message 3 of 3
(4,407 Views)