126
Views
9
Solved
###### diff between two date time
Question

Hello,

i want to calcul the diffence betwenn two date :

date A :12/01/2012 08:36:00

date B 14/01/2012 11:25:00

i want to find 2 day 2hours and 49 minutes.

what can i do?

When i want to calculate 2 hours i have 3049 minute is it 51 hourss it is 48 hours ( 2 days) and 3 hours (it would be 2) Raphael Ranieri
MVP
Solution

Hi Damian,

As the Agno's solution suggested, you have to get the difference in the minimal unity you need, and then convert to other unities.

For example, if you have to show a hour and minute format, you have to get the difference in minutes using DiffMinutes() and then see how many full hours and remaining minutes you have in this value.

e.g: if you have 130 minutes returned in DiffMinutes() you would have 2 full hours and 10 minutes remaining.

The same thing can be done for seconds.

If you have to show a hour, minute and second format. You have to get the difference in seconds using DiffSeconds() and then see how many full hours, full minutes and remaining seconds you have in this value.

This calc can be achieve using the example Agno posted.

Also the solution Nuno pointed, is a way of doing it, however it will return a DateTime as result, with a given day, month and year.

Cheers :)

RR Bart Nooijens

Hi Damien,

You have a few Build-in functions that you could use to achieve this. You can find them in the expression editor. I hope this helps you.

Regards,

Bart Damien Larzabal

I think but when i use it wont work like i explain

my code is

```DiffDays(GetCRSSChronologieById.List.Current.CRSSChronologie.DateHeureReprise,GetCRSSChronologieById.List.Current.CRSSChronologie.DateHeureFin)
+" jours "+
TextToInteger(((DiffHours
+ ":" +
Mod(DiffMinutes Agno Silveira
MVP

Hi Damien, Example: Regards. Nuno Reis
MVP

Hello.

The most straightforward approach is to create a new Date (start at 0 years, 0 months, 0 days, 0 hours, 0 minutes, and 0 seconds) and add to it the difference in seconds between the two dates.

AddSeconds( NullDate() , DiffSeconds(DateA, DateB) )

It works for up to 60 years.

In your case it would return 1900-01-03 02:49:00 (2 days, 2 hours, 49 minutes and 0 seconds after 1900-01-01)

To save in distinct variables, you have to do it one by one like explained above. Raphael Ranieri
MVP
Solution

Hi Damian,

As the Agno's solution suggested, you have to get the difference in the minimal unity you need, and then convert to other unities.

For example, if you have to show a hour and minute format, you have to get the difference in minutes using DiffMinutes() and then see how many full hours and remaining minutes you have in this value.

e.g: if you have 130 minutes returned in DiffMinutes() you would have 2 full hours and 10 minutes remaining.

The same thing can be done for seconds.

If you have to show a hour, minute and second format. You have to get the difference in seconds using DiffSeconds() and then see how many full hours, full minutes and remaining seconds you have in this value.

This calc can be achieve using the example Agno posted.

Also the solution Nuno pointed, is a way of doing it, however it will return a DateTime as result, with a given day, month and year.

Cheers :)

RR Damien Larzabal

thanks all Agno Silveira
MVP

Damien Larzabal wrote:

thanks all

:D Zameer Alam

We cannot use "-" in date format but if we need to find the difference between two dates we may use following equation.

```Concat("  Year = ",Concat(IntegerToText(Trunc(DiffDays(Person.DateOfBirth,CurrDate())/365)),

Concat(" , Month = ",Concat(IntegerToText(Trunc((365-((DiffDays(Person.DateOfBirth,CurrDate())/365- Trunc(DiffDays(Person.DateOfBirth,CurrDate())/365))*365))/12)),

Concat(" , Days = ",IntegerToText(Trunc((((365-((DiffDays(Person.DateOfBirth,CurrDate())/365- Trunc(DiffDays(Person.DateOfBirth,CurrDate())/365))*365))/12
)-Trunc((365-((DiffDays(Person.DateOfBirth,CurrDate())/365- Trunc(DiffDays(Person.DateOfBirth,CurrDate())/365))*365))/12
))*12))
)) )   ))``` Zameer Alam

MY ISSUE WAS I WANT TO KNOW THE EXACT AGE , IF I AM HAVING BATE_OF_BIRTH

Yesterday I was searching for a solution for this issue but i did not find the answers suitable for my issue, hence i have tried it my own and yesterday itself posted that solution here but later on i find my solution need to be more precise and should be small so i have created new one for me kindly check if it solves your problem too,

``` If(Year(Person.DateOfDeath)<>1900,"He/she already passed away on "+Person.DateOfDeath,

Concat("Year = ",Concat(Year(CurrDate())-Year(Person.DateOfBirth),Concat(", Month = ",Concat(If((Month(CurrDate())-Month(Person.DateOfBirth))<0,12+(Month(CurrDate())-Month(Person.DateOfBirth)),Month(CurrDate())-Month(Person.DateOfBirth)),Concat(", Day = ",If((Day(CurrDate())-Day(Person.DateOfBirth))>0,(Day(CurrDate())-Day(Person.DateOfBirth)),(Day(Person.DateOfBirth))-(Day(CurrDate())))))))))```
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.