Rank: Newbie
Groups: Registered
Joined: 5/11/2015(UTC) Posts: 8  Location: München Thanks: 3 times
|
Hello,
I have to timestamps '31.05.2015 23:44' and '01.06.2015 00:15'.
Which is the easiest xpath way to to get the correct difference in minutes ?
|
|
|
|
Rank: Administration
Groups: Registered, Administrators Joined: 9/15/2014(UTC) Posts: 133  Was thanked: 18 time(s) in 18 post(s)
|
Hi Rednose,
e.g.: let $begin := '31.05.2015 23:42' return let $end := '01.06.2015 00:15' return let $f := parse-dateTime( ?, '[DD].[MM].[YYYY] [HH]:[mm]' ) return let $diff := $f( $end ) - $f( $begin ) return ( minutes-from-duration($diff) + 60 * ( hours-from-duration( $diff ) + 24 * days-from-duration( $diff ) ) )
Altova MobileTogether Experts
|
 1 user thanked AFC for this useful post.
|
|
|
Rank: Newbie
Groups: Registered
Joined: 5/11/2015(UTC) Posts: 8  Location: München Thanks: 3 times
|
Hello AFC,
thanks for your quick reply. It ended up here :
declare function Str-Diff-Minutes-Int($a as xs:string, $b as xs:string) as xs:integer { let $begin := $a return let $end := $b return let $f := parse-dateTime( ?, '[YYYY]-[MM]-[DD]T[HH]:[mm]' ) return let $diff := $f( $end ) - $f( $begin ) return (minutes-from-duration($diff) + 60 * ( hours-from-duration( $diff ) + 24 * days-from-duration( $diff ) )) } For an x-path newbee it is not easy, but elegant :-)
|
|
|
|
Rank: Administration
Groups: Registered, Administrators Joined: 7/21/2014(UTC) Posts: 487
Was thanked: 83 time(s) in 83 post(s)
|
Just FYI: because MobileTogether is built upon XQuery, which is a superset of XPath, you can profit from its advanced syntax. In your case you can get rid of all return statements except the last one:
declare function Str-Diff-Minutes-Int($a as xs:string, $b as xs:string) as xs:integer { let $begin := $a let $end := $b let $f := parse-dateTime( ?, '[YYYY]-[MM]-[DD]T[HH]:[mm]' ) let $diff := $f( $end ) - $f( $begin ) return (minutes-from-duration($diff) + 60 * ( hours-from-duration( $diff ) + 24 * days-from-duration( $diff ) )) }
|
 1 user thanked bbv for this useful post.
|
|
|
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.