Format-date

Halo, I need help to display only year form a full date on a label, When i
use

format-date(2021-09-30, %Y)

It is displayed as is on the label. no formatting is done.
How can i get it to display 2021 instead of the full date on the label

Hi Mark. In order to display a formatted date in a label, you need to place
that expression inside an tag, and surround the formatting
argument in quotes. In addition, the first argument to the format-date()
function needs to be a date, rather than a string, so something like
today() or date('2021-09-30') or the path to a date question type in your
form.

So for your case, the following should work:

However, it's worth noting that if you already know the specific date you
want to display, you could simplify things and just write the string '2021'
as the label directly. That's all that the above expression will do
currently.

You can read the full documentation for the date() and format-date()
functions here:
https://confluence.dimagi.com/display/commcarepublic/CommCare+Functions

Best,
Aliza

Halo, I need help to display only year form a full date on a label, When
i use

format-date(2021-09-30, %Y)

It is displayed as is on the label. no formatting is done.
How can i get it to display 2021 instead of the full date on the label

--
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.

··· On Fri, Mar 11, 2016 at 4:10 PM, Mark Onimbo wrote: > For more options, visit https://groups.google.com/d/optout.

Thanks Alot Aliza

··· On Friday, March 11, 2016 at 4:25:14 PM UTC+2, astone wrote: > > Hi Mark. In order to display a formatted date in a label, you need to > place that expression inside an tag, and surround the formatting > argument in quotes. In addition, the first argument to the format-date() > function needs to be a date, rather than a string, so something like > today() or date('2021-09-30') or the path to a date question type in your > form. > > So for your case, the following should work: value="format-date(date('2021-09-30'), '%Y')"/> > > However, it's worth noting that if you already know the specific date you > want to display, you could simplify things and just write the string '2021' > as the label directly. That's all that the above expression will do > currently. > > You can read the full documentation for the date() and format-date() > functions here: > https://confluence.dimagi.com/display/commcarepublic/CommCare+Functions > > Best, > Aliza > > > > On Fri, Mar 11, 2016 at 4:10 PM, Mark Onimbo <oni...@unfpa.org > wrote: > > > > Halo, I need help to display only year form a full date on a label, When > i use > > > > format-date(2021-09-30, %Y) > > > > It is displayed as is on the label. no formatting is done. > > How can i get it to display 2021 instead of the full date on the label > > > > > > > > > > > > -- > > 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. >