[erlang-questions] How do I compute daytime difference properly?
Kirill Zaborski
qrilka@REDACTED
Mon May 5 20:34:21 CEST 2008
DateTime tuple (from erlang:localtime/0) has format {{Year, Month,
Day},{Hour, Minute,Second}}.
Not sure what exact meaning has you function (even if we neglect time
part), e.g. what if I subtract 12:00:00 30th of April 2008 from
12:00:00 1st of May 2008? It looks like we'll get 1000.029 but what
are the units? I'd like to get 1 day or 86400 seconds.
On Mon, May 5, 2008 at 10:07 PM, Greg Burri <greg.burri@REDACTED> wrote:
> Hi,
> Maybe like this :
>
> delta_date_ms(D1, D2) ->
> 1000000000 * abs(element(1, D1) - element(1, D2)) + 1000 *
> abs(element(2, D1) - element(2, D2)) + trunc(abs(element(3, D1) -
> element(3, D2)) / 1000).
>
>
> /Greg
>
> On Sat, May 3, 2008 at 9:10 PM, Igor Ribeiro Sucupira <igorrs@REDACTED> wrote:
> > I think there's no easier way of doing that.
> >
> > 2008/5/3 Kirill Zaborski <qrilka@REDACTED>:
> >
> >
> > >
> > > Reading calendar module documentation I see the note:
> > > "For computing differences between epochs in time, use the functions
> > > counting gregorian days or seconds. If epochs are given as local time, they
> > > must be converted to universal time, in order to get the correct value of
> > > the elapsed time between epochs. Use of the function time_difference/2 is
> > > discouraged."
> > > But it's not quite clear to me...
> > > E.g. I have 2 values LocalTime1 and LocalTime2 which are somewhat like
> > > tuples erlang:localtime/0 and need to compute time difference e.g. in
> > > seconds. So should I then convert this values to UTC and then use
> > > calendar:datetime_to_gregorian_seconds/1 and then do the subtraction?
> > > Or maybe there is some easier way?
> > >
> > > Best regards,
> > > Kirill.
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://www.erlang.org/mailman/listinfo/erlang-questions
> >
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
More information about the erlang-questions
mailing list