02-15-2012 03:17 PM
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
02-16-2012 02:19 AM - edited 02-16-2012 02:24 AM
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...
02-16-2012 10:56 AM
(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
02-17-2012 11:26 AM
Hello Roberto, Luis:
Thanks for your response,was useful.
@Luis
The calculation of the date is correct, thanks for your code.
Best Regards.
Alex