Good evening !
I am facing an error I don't understand (I am a bit tired
) :
I use this expression in a calculate question in order to get current time.
format-date-time(once(now()),"%H:%M:%S")
But collect throws an error "XPatth evaluation type mismatch :The value "19:31:45" can't be converted to a date."
But the doc makes me think it is possible :
format-date-time(dateTime, format)
Returns dateTime as a string formatted as defined by format.
The identifiers list in format-date() are available, plus the following:
%H 0-padded hour (24-hr time)
%h hour (24-hr time)
%M 0-padded minute
%S 0-padded second
%3 0-padded millisecond ticks.
Thanks a lot for the help !
I have a similar field, but it references a separate once(now())
field and works fine.
I can't get the same error with your calculate, but I can get it to not work depending on where the once
is.
The following calculates were all in text
fields
doesn't work: format-date-time(once(now()),"%H:%M:%S")
works: once(format-date-time(now(),"%H:%M:%S"))
works: once(format-date-time(once(now()),"%H:%M:%S"))
So, move the once
outside the format-date-time
or add an extra once
Thanks a lot Andrew ! I'll try it tomorrow.
1 Like

once() is a rather odd function, in that it checks whether the calculation's associated binding nodeset already has a value or not, before determining whether to perform the calculation. So I'd recommend not trying to mix-n-match using it inside as an operand in a larger calculation (or for that matter more than once [sic]!), but as @ahblake suggests always use it on the 'outside' of the calculation so that you dont confuse yourself as to what is actually going on.
Thanks a lot for the explanation Gareth !
indeed, the error does not always occur...