Calculating days between two dates

Hey there,

I've a scenario where the enumerators enter a Nepali date and by
calculating the date-difference with today(), number of days are
achieved. To perform this, I created an excel (uploaded as media file to
the survey form) reference that has the mappings of all relevant Nepali
dates with the English dates.

I created a survey form that fetches the equivalent English date from an
entered Nepali date from the reference excel file fine
. How can the day
differences between those two dates be calculated? I've attached the xls
form and the reference excel (date_key column in the media file is the
input entered in the survey form and datevalue is the respective English
date). I've given few tries here and there doing researches but none seems
to be working. Any lead is much appreciated.

survey_form.xls (29.5 KB)

datedata_test.csv (109 Bytes)

Hi Changbang,

I was looking at your problem, and based on the form + data file provided,
and found that you had made a number of mismatched types for your input.

  • To convert date to decimal, they first must be in date type. You can
    either specify this type to data input; or in your case, imported data must
    be converted to date using function: date(yyyy-mm-dd)
  • I do not have comment on other text input fields with calculation,
    which I think is good to optimise form size, but you may want to take extra
    care for type input.

2 edited files are attached, of which xls file is possible to render to xml
form, but not fully validated, due to imported data is not present at the
time of validation. Anyway, it works out the date difference, between
imported date and today() with minor fluctuation of 1 to 2 hour.

Note: Your data file's date was formatted to yyyy-mm-dd for data conversion
compatibility. IF you keep previous format, you will need to format it in
your XLS form before converting it to date type.

Interesting problem though. I've learnt to use calculation for input type
instead of using calculate type to do calculation. This is good to replace
default value which doesn't support dynamic variable in current ODK.

Hung.

survey_form.xls (9 KB)

datedata_test.csv (109 Bytes)

··· On Wednesday, 28 October 2015 09:47:53 UTC, ChangbangMobs wrote: > > Hey there, > > I've a scenario where the enumerators enter a *Nepali date* and by > calculating the date-difference with today(), *number of days* are > achieved. To perform this, I created an excel (uploaded as *media file* > to the survey form) reference that has the mappings of all relevant Nepali > dates with the English dates. > > I created a survey form *that fetches the equivalent English date from an > entered Nepali date from the reference excel file fine*. How can the day > differences between those two dates be calculated? I've attached the xls > form and the reference excel (date_key column in the media file is the > input entered in the survey form and datevalue is the respective English > date). I've given few tries here and there doing researches but none seems > to be working. Any lead is much appreciated. >

Thanks Hung!! I did few rounds of hits and trials and was able to achieve
the day difference. Yeah, it was always there (obv. programming logic) that
it had to do with compatible formatting of the date to make computations. I
am sure your attachment will help others going through the problem. Thanks
again for the reply and the attachment!!

··· On Wednesday, October 28, 2015 at 3:32:53 PM UTC+5:45, ChangbangMobs wrote: > > Hey there, > > I've a scenario where the enumerators enter a *Nepali date* and by > calculating the date-difference with today(), *number of days* are > achieved. To perform this, I created an excel (uploaded as *media file* > to the survey form) reference that has the mappings of all relevant Nepali > dates with the English dates. > > I created a survey form *that fetches the equivalent English date from an > entered Nepali date from the reference excel file fine*. How can the day > differences between those two dates be calculated? I've attached the xls > form and the reference excel (date_key column in the media file is the > input entered in the survey form and datevalue is the respective English > date). I've given few tries here and there doing researches but none seems > to be working. Any lead is much appreciated. >

Note that there are a number of issues with date arithmetic (adding /
subtracting). Depending upon your time zone, and time changes (e.g.,
daylight savings time vs. standard time), you may experience +/- 1 day
errors.

··· On Tue, Nov 3, 2015 at 2:21 AM, ChangbangMobs wrote:

Thanks Hung!! I did few rounds of hits and trials and was able to achieve
the day difference. Yeah, it was always there (obv. programming logic) that
it had to do with compatible formatting of the date to make computations. I
am sure your attachment will help others going through the problem. Thanks
again for the reply and the attachment!!

On Wednesday, October 28, 2015 at 3:32:53 PM UTC+5:45, ChangbangMobs wrote:

Hey there,

I've a scenario where the enumerators enter a Nepali date and by
calculating the date-difference with today(), number of days are
achieved. To perform this, I created an excel (uploaded as media file
to the survey form) reference that has the mappings of all relevant Nepali
dates with the English dates.

I created a survey form that fetches the equivalent English date from
an entered Nepali date from the reference excel file fine
. How can the
day differences between those two dates be calculated? I've attached the
xls form and the reference excel (date_key column in the media file is the
input entered in the survey form and datevalue is the respective English
date). I've given few tries here and there doing researches but none seems
to be working. Any lead is much appreciated.

--

Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en


You received this message because you are subscribed to the Google Groups
"ODK Community" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com