LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Operaciones entre fechas

Solved!
Go to solution

Hola, necesito ayuda con las fechas.

Tengo 2 fechas (struct tm), lo que necesito saber si se puede hacer operaciones en base a las horas con estas 2 fechas.

Principalmente agregar y quitar horas.

 

Cualquier ayuda o comentario es bienvenido, muchas gracias.

Alex

0 Kudos
Message 1 of 4
(3,000 Views)

Hola, se pueden hacer operaciones entre fechas pasando los valores de las estructuras a la función mktime () que restituye un valor en segundos. La operación inversa es localtime () u gmtime ().

 

Analogamente, los valores pueden pasarse a la función MakeDateTime (). GetDateTimeElements () se utiliza para pasar del valor en segundos a la correspondiente fecha.



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?
0 Kudos
Message 2 of 4
(2,997 Views)
Solution
Accepted by topic author Alejandro López Martínez

Hola, aquí tienes un ejemplo de operaciones en el tiempo; puedes ejecutar estas líneas en la ventana de la Interactive Execution.

 

#include <ansi_c.h>
#include <utility.h>
static time_t t;
static struct tm *tm;

t = time (NULL);
tm = localtime (&t);
DebugPrintf ("Local time is %d-%d-%d   %d:%02d\n", 
    tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min);
DebugPrintf ("Adding 2 hours...\n");
t += 3600 * 2;
tm = localtime (&t);
DebugPrintf ("New time is %d-%d-%d   %d:%02d\n", 
    tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min);
DebugPrintf ("Adding 2 days...\n");
t += 86400 * 2;
tm = localtime (&t);
DebugPrintf ("New time is %d-%d-%d   %d:%02d\n", 
    tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min);

 Las operaciones con MakeDateTime y las funciones relacionadas son similares.

 



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?
0 Kudos
Message 3 of 4
(2,994 Views)

Hola Roberto:

 

Muchas gracias, son exactamente lo que necesito, gracias por tu soporte.

 

Saludos...

Alex

0 Kudos
Message 4 of 4
(2,986 Views)