Subject:Subtract times Author:(Deleted User) Date:14 Nov 2008 09:55 AM
Hi you all,
I want to subtract two time fields. Googling learned me that the op:subtract function would work and that if you add this namespace prefix you can just deduct to variables. I think I am close to a solution with the code below, however it keeps telling me:
Static type error. Types 'element(DateEnd, xs:anyType)' and 'element(DateStart, xs:anyType)' are invalid argument types for binary operator '-'.
though I have associated a schema (right mouse button on doc node in source doc of xquery) in which these two fields are defined as xsd:date fields. Can you assist?
declare variable $arg1 as element(DateStart) external;
declare variable $arg2 as element(DateEnd) external;
The returned values are xs:duration types; you can use various functions to handle xs:duration, like hours-from-duration(), days-from-duration(), ...; a word of caution; those functions are specified to be less smart than you might think: hours-from-duration("P1D") is 0 (not 24 as I expected); days-from-duration("P1D") is 1.
Subject:Subtract times Author:(Deleted User) Date:15 Nov 2008 03:56 AM
Morning!
Ok, waking up and of course right away curious if there is a post. Now got the answer, cause I realized my types were xs:time but if was just giving back <DateStart>11:00:00-10:00:00</DateStart>. Moved the subtraction to the top of my xquery file, assigned the subtraction outcome to $arg3 and placed {$arg3} in my xml tag. Et voila!
Thank you so much!
Cynthia
for $row in doc('file:///e:/Synergy_ASP/HR/Verlofaanvragen/Workflow_Verlof_basis.xml')/root/row
let $arg1 := xs:time($row/DateStart),
$arg2 := xs:time($row/DateEnd),$arg3:= ($arg2)-($arg1)