Is there a way to get the week number out of a date?

(Guillaume Deflaux) #1

Hi,

The ‘format-date’ function cannot give return it. Any idea how to compute
it?

Thanks

(Clayton Sims) #2

Guillaume,

Do you mean the Day of The Week (1-7) or “the current week of the year”
(1-52)?

-Clayton

··· On Wed, Mar 25, 2015 at 2:24 PM, Guillaume Deflaux < deflaux.guillaume@gmail.com> wrote:

Hi,

The ‘format-date’ function cannot give return it. Any idea how to compute
it?

Thanks


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

(Guillaume Deflaux) #3

I mean the week number of the year (1-52).

··· On Wednesday, March 25, 2015 at 8:18:26 PM UTC, Clayton Sims wrote: > > Guillaume, > > Do you mean the Day of The Week (1-7) or "the current week of the year" > (1-52)? > > -Clayton > > On Wed, Mar 25, 2015 at 2:24 PM, Guillaume Deflaux <deflaux....@gmail.com > wrote: > >> Hi, >> >> The 'format-date' function cannot give return it. Any idea how to compute >> it? >> >> Thanks >> >> -- >> You received this message because you are subscribed to the Google Groups >> "commcare-users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to commcare-user...@googlegroups.com . >> For more options, visit https://groups.google.com/d/optout. >> > >
(Clayton Sims) #4

Guillaume,

I don’t think we support a super easy way to get that, but this calculation
seems like it does the right thing to me.

int((now() - date(concat(format-date(now(),’%Y’),’-01-01’))) div 7)

-Clayton

··· On Thu, Mar 26, 2015 at 5:33 AM, Guillaume Deflaux < deflaux.guillaume@gmail.com> wrote:

I mean the week number of the year (1-52).

On Wednesday, March 25, 2015 at 8:18:26 PM UTC, Clayton Sims wrote:

Guillaume,

Do you mean the Day of The Week (1-7) or “the current week of the year”
(1-52)?

-Clayton

On Wed, Mar 25, 2015 at 2:24 PM, Guillaume Deflaux <deflaux....@gmail.com wrote:

Hi,

The ‘format-date’ function cannot give return it. Any idea how to
compute it?

Thanks


You received this message because you are subscribed to the Google
Groups “commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to commcare-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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

(Guillaume Deflaux) #5

Yes good idea. Thanks.

··· On Thursday, March 26, 2015 at 2:21:52 PM UTC, Clayton Sims wrote: > > Guillaume, > > I don't think we support a super easy way to get that, but this > calculation seems like it does the right thing to me. > > int((now() - date(concat(format-date(now(),'%Y'),'-01-01'))) div 7) > > -Clayton > > On Thu, Mar 26, 2015 at 5:33 AM, Guillaume Deflaux <deflaux....@gmail.com > wrote: > >> I mean the week number of the year (1-52). >> >> On Wednesday, March 25, 2015 at 8:18:26 PM UTC, Clayton Sims wrote: >>> >>> Guillaume, >>> >>> Do you mean the Day of The Week (1-7) or "the current week of the year" >>> (1-52)? >>> >>> -Clayton >>> >>> On Wed, Mar 25, 2015 at 2:24 PM, Guillaume Deflaux < deflaux....@gmail.com> wrote: >>> >>>> Hi, >>>> >>>> The 'format-date' function cannot give return it. Any idea how to >>>> compute it? >>>> >>>> Thanks >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "commcare-users" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to commcare-user...@googlegroups.com. >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> >>> -- >> You received this message because you are subscribed to the Google Groups >> "commcare-users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to commcare-user...@googlegroups.com . >> For more options, visit https://groups.google.com/d/optout. >> > >
(Ahmed Mohammed) #6

Dear Clayton,

thank you for this idea, can you give example .
because I don’t know how and where I use this validation.

best,

(zekarias) #7

Clayton,

What if, you have a question where you ask the date, and would like to use the answer to calculate the week number:

Using date_of_choice (the date of answer) in place of the first now() does the work; but, only the week start day is Tuesday.
: int((#form/date_of_choice - date(concat(format-date(now(), ‘%Y’), ‘-01-01’))) div 7)

(Clayton Sims) #8

Since the calculation listed doesn’t depend on any time components (just date components), you can replace “now()” in that expression with “date(#form/path/to_your_question”) and it should provide the same output.

-Clayton