Topic: Date Interval (year, month, day)

Hi guys
I have two separate dates and what I need is that years,months and days between these 2 date fields are calculated
this is for the purpose of calculating the age of a patient when He/She is hospitalized
the attached sample only shows days
thanks alot

Post's attachments

Attachment icon Age.zip 333.6 kb, 24 downloads since 2024-05-18 

Re: Date Interval (year, month, day)

Hi,


Calculation example. Calculation as a function. The input is two dates in TDateTime format, the output is the sign and values of years, months, days, hours, minutes, seconds.

Post's attachments

Attachment icon date tdt diff func.zip 90.75 kb, 29 downloads since 2024-05-18 

Re: Date Interval (year, month, day)

WOW
thank you sparrow as always
that's exactly what I needed

Re: Date Interval (year, month, day)

It is also possible this way


  Form1.Edit1.Text := sqlexecute('SELECT PRINTF(''YMD: %04d-%02d-%02d'', '+
        'alldays / 365250 , (alldays % 365250) / 30437, ( (alldays % 365250) % 30437)/1000 ) '+
        'FROM (SELECT (JULIANDAY('+Form1.DateTimePicker1.sqlDate+') - JULIANDAY('+Form1.DateTimePicker2.sqlDate+'))*1000 AS alldays  ) AS t;');