Año(s), mes(es) y dia(s) transcurridos entre dos fechas

Source code related resources

Moderator: Rathinagiri

User avatar
tave2009
Posts: 61
Joined: Tue Jul 14, 2009 3:33 am
Location: San Francisco, Córdoba, Argentina.

Año(s), mes(es) y dia(s) transcurridos entre dos fechas

Post by tave2009 »

Hola Amigos:

En esta oportunidad les acerco una función para obtener: año(s), mes(es) y día(s), entre dos fechas ;)

:arrow: CalculaAMD( <FechaInicial>, <FechaFinal>) ==> cResultado

He buscado por los foros y no encontré algo que funcionara correctamente, por lo tanto decidí hacer mi propia función.
Espero sea de utilidad para quien quiera saber la edad o el tiempo transcurrido entre dos fechas.
El código fuente puede contener errores. Lo he 'testeado' sin novedad, pero ...
Saludos.
Walter.

Google Translation:

Hello Friends:

This time I approached a role for the year (s), month (s) and day (s) between two dates;)

: arrow: CalculaAMD (<FechaInicial>, <FechaFinal>) ==> cResultado

I've searched the forums and did not find anything that would work properly, so I decided to make my own function.
Hope this helps for those who want to know the age or the time between two dates.
The source code may contain errors. I've 'tested' without incident, but ...
Greetings.
Walter.
Attachments
amd.zip
(5.3 KiB) Downloaded 460 times
Nada se pierde. Todo se transforma. (Lavoussier)
Nothing is lost. Everything changes.
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Año(s), mes(es) y dia(s) transcurridos entre dos fechas

Post by Rathinagiri »

Thanks. It will be really useful.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Año(s), mes(es) y dia(s) transcurridos entre dos fechas

Post by esgici »

Hola Walter

It's nice you write in two languages ;)
tave2009 wrote:This time I approached a role for the year (s), month (s) and day (s) between two dates;)
...
I've searched the forums and did not find anything that would work properly,
Thanks to sharing :)

viewtopic.php?f=9&t=7&p=13

Saludos
Viva INTERNATIONAL HMG :D
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Año(s), mes(es) y dia(s) transcurridos entre dos fechas

Post by Rathinagiri »

Hi Esgici,

I had made an assumption that months have 30 days, where as Walter is not assuming things and count for actual number of days, months and years.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Año(s), mes(es) y dia(s) transcurridos entre dos fechas

Post by esgici »

rathinagiri wrote:Hi Esgici,

I had made an assumption that months have 30 days, where as Walter is not assuming things and count for actual number of days, months and years.
Thanks to you both :)

Viva HMG :D
Viva INTERNATIONAL HMG :D
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Re: Año(s), mes(es) y dia(s) transcurridos entre dos fechas

Post by Pablo César »

rathinagiri wrote:where as Walter is not assuming things and count for actual number of days, months and years.
Yeah, this is a good differance !

Thank you Walter for sharing with us, I had appointed to your post by coincidence for same matter in other forum.

Muchas gracias Walter y felicitaciones !

One question Walter: Not all february has 28 days, did you treat that ?

In Spanish: Walter, no todos los meses de febrero tienen 28 dias, has tratado eso en tu rutina de código ?
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Año(s), mes(es) y dia(s) transcurridos entre dos fechas

Post by Rathinagiri »

Yes, he has.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Re: Año(s), mes(es) y dia(s) transcurridos entre dos fechas

Post by Pablo César »

Ahhh yes amigio Rathinagiri, Walter has treated this in:

if nMesActual == 2 so it is not using vetor...

Thanks !
Last edited by Pablo César on Fri Mar 15, 2013 4:34 pm, edited 1 time in total.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
Leopoldo Blancas
Posts: 388
Joined: Wed Nov 21, 2012 7:14 pm
Location: México

Re: Año(s), mes(es) y dia(s) transcurridos entre dos fechas

Post by Leopoldo Blancas »

Hola a todos...

Yo hice esta rutina para calcular la Edad o antigüedad entre dos fechas... Espero les sirva.
*------------------------------------------------------------------------------------------------------------------------------------------------
Hi all ...

I did this routine to calculate the age or seniority between two dates ... I hope they can.

Code: Select all

FUNCTION CalculaEdad(cFechaNaci,cFechaHoy)
LOCAL FechaNaci:= CtoD(cFechaNaci)
LOCAL nAnoNaci := YEAR(FechaNaci)
LOCAL nMesNaci := MONTH(FechaNaci)
LOCAL nDiaNaci := DAY(FechaNaci)
LOCAL nAnoHoy       
LOCAL nMesHoy        
LOCAL nDiaHoy        
LOCAL nDifAnos  := 0
LOCAL nDifMeses := 0
LOCAL nDifDias  := 0
LOCAL aEdad

LOCAL lAnosMenos := .F.

LOCAL aMesesDias := {}
LOCAL aBisiestos := {1904, 1908, 1912, 1916, 1920, 1924, 1928, 1932, 1936, 1940, 1944, 1948, 1952, 1956, 1960, 1964, 1968, 1972, 1976, 1980, 1984, 1988, 1992, 1996, 2000, 2004, 2008,2012,2016,2020,2024,2028,2032,2036,2040,2044,2048,2052,2056,2060,2064,2068,2076,2080,2084,2088,2092,2096,2100}
LOCAL lBisiesto := .F.


IF PCOUNT()=0
   MsgBox("Falta un parametro String Tipo Fecha '01/01/1900'")
   RETURN NIL
ELSEIF PCOUNT()=1
   nAnoHoy := YEAR(DATE())
   nMesHoy := MONTH(DATE())
   nDiaHoy := DAY(DATE())
ELSEIF PCOUNT()=2  
   nAnoHoy := YEAR(CtoD(cFechaHoy))
   nMesHoy := MONTH(CtoD(cFechaHoy))
   nDiaHoy := DAY(CtoD(cFechaHoy))
ENDIF

IF PosiArray(aBisiestos,nAnoNaci) != 0
   lBisiesto := .T.
ENDIF

AADD(aMesesDias,{1,'ENERO',31})
AADD(aMesesDias,{2,'FECBRERO',IIF(lBisiesto,29,28)})
AADD(aMesesDias,{3,'MARZO',31})
AADD(aMesesDias,{4,'aBRIL',30})
AADD(aMesesDias,{5,'MAYO',31})
AADD(aMesesDias,{6,'JINIO',30})
AADD(aMesesDias,{7,'JULIO',31})
AADD(aMesesDias,{8,'AGOSTO',31})
AADD(aMesesDias,{9,'SEPTIEMBRE',30})
AADD(aMesesDias,{10,'OCTUBRE',31})
AADD(aMesesDias,{11,'NOVIEMBRE',30})
AADD(aMesesDias,{12,'DICIEMBRE',31})

*--------------------------------------------PARA CALCULAR LOS AÑOS
IF nMesNaci < nMesHoy
   nDifAnos  := nAnoHoy - nAnoNaci
ELSEIF nMesNaci == nMesHoy
   nDifAnos  := nAnoHoy - nAnoNaci
ELSEIF nMesNaci > nMesHoy
   nDifAnos := (nAnoHoy - nAnoNaci)-1
   lAnosMenos := .T.
ENDIF

*------------------------------------PARA CALCULAR LOS MESES Y DÍAS
IF nMesNaci < nMesHoy
   nDifMeses  := (nMesHoy - nMesNaci)
   nDifDias  := Abs(nDiaHoy - nDiaNaci)
ELSEIF nMesNaci == nMesHoy
   IF nDiaNaci < nDiaHoy
      nDifMeses  := nMesHoy - nMesNaci
      nDifDias  := nDiaHoy - nDiaNaci
   ELSEIF nDiaNaci == nDiaHoy
      nDifMeses  := nMesHoy - nMesNaci
      nDifDias := 0
   ELSEIF nDiaNaci > nDiaHoy
      nDifMeses  := nMesHoy-1
      lMesesMenos:= .T.
      nDifDias := IIF(nMesNaci=1,aMesesDias[12][3]-nDiaNaci + nDiaHoy,aMesesDias[nMesNaci-1][3]-nDiaNaci + nDiaHoy)
   ENDIF   
ELSEIF nMesNaci > nMesHoy
   nDifMeses := (12-nMesNaci)+nMesHoy 
   nDifDias  := Abs(nDiaHoy - nDiaNaci)
ENDIF

aEdad:= {nDifAnos,nDifMeses,nDifDias}

RETURN aEdad
Saludos
Polo
*-----------------------------------------------
regards
Polo
Leopoldo Blancas
Posts: 388
Joined: Wed Nov 21, 2012 7:14 pm
Location: México

Re: Año(s), mes(es) y dia(s) transcurridos entre dos fechas

Post by Leopoldo Blancas »

Hola Walter...

Gracias por compartir. :D

Saludos
Polo
*---------------------------------------------------------------------
Hello Walter ...

Thanks for sharing. : D

regards
Polo
Post Reply