1 (edited by mathmathou 2015-03-14 01:19:01)

Topic: [SOLVED] Difference between 2 dates + time

Hello Dimtry,


I've searched the forum and found some partial answers to my upcoming question, but I was unable to completely solve my problem.


I would like to make calculations on dates.


Getting the elapsed time bewteen two dates is easy with

SecondsBetween
MinutesBetween
HoursBetween
DaysBetween

and so on


But that is when you only have a date picker.


FIRST QUESTION : can I have a datepicker with date AND time ?
I tried something like 'yyyy-mm-dd hh:mm' in the datepicker format and it works but...  here comes the second question


SECOND QUESTION : how do you make calculation on those datepickers with date AND time ?
I've tried

SecondsBetween(Form1.beginhour.DateTime,Form1.endhour.DateTime)

with beginhour 2015-03-13 10:30 and endhour 2015-03-13 11:30 and the result should be 3600


But it returns 0.


Did I miss something ? Is the format wrong ? Or is it just impossible at the moment maybe ?


Thanks in advance


Cheers


Math


PS : this is not to calculate the age of a person smile

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: [SOLVED] Difference between 2 dates + time

If you need to save to the database at the same time the date and time, please read more info about property Calendar:
http://myvisualdatabase.com/help_en/com … icker.html


For using Date and Time, you need two DateTimePickers
Example:

PickerDate (property Kind=Date)
PickerTime (property Kind=Time)

var
    DateTime1, DateTime2: TDateTime;
begin
    DateTime1 := Trunc(Form1.PickerDate.DateTime) +  Frac(Form1.PickerTime.DateTime);
    DateTime2 := Trunc(Form1.PickerDate2.DateTime) +  Frac(Form1.PickerTime2.DateTime);

    ShowMessage( SecondsBetween(DateTime1,DateTime2) );
Dmitry.

3 (edited by mathmathou 2015-03-14 01:30:54)

Re: [SOLVED] Difference between 2 dates + time

Hello Dimtry and thank you for your help, question is solved.


I post my project as an example if someone needs it or if you want to keep it for further reference


I used 2 different approaches for calculating the result :


1- conversion in seconds and then divisions and modulos for each steps

2- direct conversion in days/hours/minutes wit the between method  and modulos


Each method gives the same result (script is commented in english).


Thanks again for you valuable help.


Cheers


Mathias

PS1 : version of MVDB is 1.50
PS2 : no guaranty that it's 100% bug free smile

http://i.imgur.com/uxsAZ6m.jpg

Post's attachments

Attachment icon diff_between_dates.zip 335.04 kb, 710 downloads since 2015-03-14 

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: [SOLVED] Difference between 2 dates + time

Essa instrução funciona no MVD 1.46. Calcula diferença entre duas datas em número de anos, meses e dias. Demorou, mas conseguir montar algo que me atende.


UPDATE Ocorrencias SET
            ano_decorrido = round((julianday('now') - julianday(Data))/365.25-0.5),
            mes_decorrido = round((julianday('now') - julianday(Data)- round((julianday('now') - julianday(Data))/365.25-0.5)*365.25)/30.41-0.5),
            dia_decorrido = round(round((julianday('now') - julianday(Data)- round((julianday('now') - julianday(Data))/365.25-0.5)*365.25))-
round((julianday('now') - julianday(Data)- round((julianday('now') - julianday(Data))/365.25-0.5)*365.25)/30.41-0.5)*30.41-0.5)

WHERE Date('now')>Ocorrencias.Data

Roberto Alencar