LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Sumar 100 años a la fecha actual

Hola:

 

Me podrían ayudar con el siguiente problema, tengo que calcular la fecha de hoy más 100 años, pero al momento de sumarle los 100 años (en segundos, se muestra  una fecha de 1975.

 

Estuve probando con diferentes valores y máximo que acepto el time_t fue 4294967375, y arroja la fecha de 07/02/2036 06:28:15 UTC, que esta muy lejano a los 100 años que requiero.

 

Uso la versión LabWindows CVI 2009SP1, pero apenas se adquirió la versión 2010, alguna de estas 2 versiones soporta lo que requiero.

 

De antemano muchas gracias por su ayuda.

 

Saludos...

Alex

0 Kudos
Message 1 of 4
(2,882 Views)

Esto es bastante claro si consideras que el tipo time_t realmente es un integro sin signo, cuyo máximo justamente es 4.294.967.295, que se corresponde a alguna fecha alrededor del 2036. No conozco funciones para pasar de esto límite.

Parece que las funciones nativas del CVI (MakeDateTime y otras de la librería userint) padecen del mismo límite, lo que es evidenciado en la ayuda en línea del comando (límites del campo 'year': 1900-2035).

 

Pasando al CVI2010 no hay variaciones, por lo menos en la versión de 32-bits: a ver si en la 64-bits se pasa este límite...

 



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,877 Views)

(I apologize for writing in English, but my Spanish isn't good enough to write in)

 

There is a time library in the CVI utility library that supports the operation you're trying to perform. Here's some sample code that adds 100 years to the current date/time:

 

CVIAbsoluteTimenow, then;
CVITimeIntervalhundredYears;

doublemillisecond;

unsigned inweekday, second, minute, hour, day, month, year;

 

CVITimeIntervalFromTimeUnit (CVITimeUnitDays, 365.25 * 100, &hundredYears);

GetCurrentCVIAbsoluteTime (&now);
AddToCVIAbsoluteTime (now, hundredYears, &then);
CVIAbsoluteTimeToLocalCalendar (then, &year, &month, &day, &hour, &minute, &second, &millisecond, &weekday);

 

Note that the maximum unit that you can pass to the CVITimeIntervalFromTimeUnit function is "days". This is because the exact length of a month, or of a year, isn't well defined (because years can have 365 or 366 days). I'm using 365.25 as a rough approximation, but you might have to do something more precise than that, depending on how leap years affect your calculation.

 

Luis

0 Kudos
Message 3 of 4
(2,868 Views)

Hello Roberto, Luis:

 

Thanks for your response,was useful.

 

@Luis

The calculation of the date is correct, thanks for your code.

 

Best Regards.

Alex

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