Support Forum

Ask questions and get help from MobileTogether experts.
MobileTogether Product Information
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
View
Go to last post Go to first unread
Rednose  
#1 Posted : Monday, June 1, 2015 7:46:44 AM(UTC)
Rednose

Rank: Newbie

Groups: Registered
Joined: 5/11/2015(UTC)
Posts: 8
Germany
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 ?
AFC  
#2 Posted : Monday, June 1, 2015 10:59:17 AM(UTC)
AFC

Rank: Administration

Groups: Registered, Administrators
Joined: 9/15/2014(UTC)
Posts: 133
Austria

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
thanks 1 user thanked AFC for this useful post.
Rednose on 6/1/2015(UTC)
Rednose  
#3 Posted : Monday, June 1, 2015 2:23:49 PM(UTC)
Rednose

Rank: Newbie

Groups: Registered
Joined: 5/11/2015(UTC)
Posts: 8
Germany
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 :-)
bbv  
#4 Posted : Monday, June 1, 2015 9:16:33 PM(UTC)
bbv

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 ) ))
}
thanks 1 user thanked bbv for this useful post.
Rednose on 6/1/2015(UTC)
Users browsing this topic
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.