XPath and Date Comparisons - InfoPath Dev
in

InfoPath Dev

XPath and Date Comparisons

Last post 04-22-2015 09:39 AM by Michael71. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 08-13-2010 12:53 PM

    XPath and Date Comparisons

    Hello again great forum,

    NI is a XPathNodeIterator
    DOM is a XPathNavigator

    NI = DOM.Select("/dfs:myFields/dfs:dataFields/dfs:Requests[@Begin_Date > '#6/1/1978#' ]", Me.NamespaceManager) 

    In the InnerXML, Begin_Date looks like this:      Begin_Date="2010-06-01 00:00:00"

    I need "2010-06-01 00:00:00" and '#6/1/1978#' to both be recognized as dates so that I can do a comparison. When I run it now, I get a 0 Node Count where of course 2010 is greater than 1978. Any thoughts on what I am doing wrong?

    Thanks in advance,

    Pinback

  • 08-13-2010 03:45 PM In reply to

    Re: XPath and Date Comparisons

    Hi Pinback,

    We've had so many questions about dates that we finally decided to add a Date Diff function to qRules v2.2 (also now includes Format Date). You can add qRules to forms which already have code too: http://www.infopathdev.com/files/folders/qrules/entry56111.aspx.

    Qdabra pays for this free forum and one way we defray the cost is by selling inexpensive tools like qRules. The trial download is free and you can get a discount on the $199 price if you send us a 3-4 sentence testimonial of how you liked it.

    Thanks for your support,

    Patrick Halstead
    Project Manager at Qdabra
  • 08-13-2010 06:20 PM In reply to

    Re: XPath and Date Comparisons

    Thanks Patrick,

    Unfortunately, it is not up to me what software my organization uses, so I need to seek an XPath solution.

    Anyone have an idea? :)

    When I try to embed a function to do the work (example fn:year-from-dateTime), I get told it is an unknown function. I've tried 10 different functions...same result.

    Thanks in advance,

    Pinback

  • 08-13-2010 08:45 PM In reply to

    Re: XPath and Date Comparisons

    Pinback:
    I need "2010-06-01 00:00:00" and '#6/1/1978#' to both be recognized as dates so that I can do a comparison. When I run it now, I get a 0 Node Count where of course 2010 is greater than 1978. Any thoughts on what I am doing wrong?

    Why do you "need" to use a date format like #6/1/1978#?  XML dates are of the format YYYY-MM-DD followed by Thh:mm:ss if the time is included.  @Begin_Date > '1978-06-01' should find you the dates you are looking for.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 08-14-2010 05:55 AM In reply to

    Re: XPath and Date Comparisons

     Hi Pinback, by default greater than or less than(<>) just don't work on string. You have to convert your @begin_date as a date or number. I have some good result if I convert them as number here my filter :

    [number(translate(translate(translate(.,'-',''),' ',''),':','')) > number('19780601000000')]. As you see I concatenate your 2 variables to make a big number, so it's important to have exactly the same format.

  • 08-14-2010 06:39 AM In reply to

    Re: XPath and Date Comparisons

    Jimmy,

    Thanks! You are correct...there is no "need" for my date to be formatted any particular way. I just want to get it to work. :)

    Potemkine,

    Thank you for this, I will try it first thing Monday morning.

     

    Pinback

  • 08-14-2010 07:48 AM In reply to

    Re: XPath and Date Comparisons

    Cool.

    Potemkine is right; you can't directly use > or < with dates and if you're writing code you'll need to do something to strip out the punctuation, like in the example Potemkine has given.

    In rules, conditional formatting, etc. inside the InfoPath designer, you can use msxsl:string-compare():

     dfs:myFields/dfs:dataFields/dfs:Requests[msxsl:string-compare(@Begin_Date, '1978-06-01') = 1]

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 09-20-2010 01:51 PM In reply to

    Re: XPath and Date Comparisons

    Sorry it took me so long to get back to this, but I finally did today.

     It worked!

     

    Thank you all so much for your help on this one. :)

     Pinback

  • 04-22-2015 09:39 AM In reply to

    • Michael71
    • Top 50 Contributor
      Male
    • Joined on 10-07-2006
    • Mclean, Virginia-USA
    • Posts 283

    Re: XPath and Date Comparisons

     Can you post your answer for other InfoPath Developers?

     

    Michael

Page 1 of 1 (9 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.