Using Xpath to display only the year? - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Using Xpath to display only the year?

Last post 07-24-2008 02:20 AM by kimospeed. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 07-17-2008 11:27 AM

    • jrudolph
    • Top 150 Contributor
      Male
    • Joined on 07-02-2008
    • Orlando, FL
    • Posts 67

    Using Xpath to display only the year?

    I am very new to everything XML and InfoPath.  I have a need to have a text box which, by default, will automatically displays only the current year, not the full date.  I have very limited knowledge of how to use the Xpath feature when setting the default formula. The text box properties are currently to: Data type: Date.

    I hope this makes since, any help would greatly be appreciated.

    Filed under:
  • 07-17-2008 11:48 AM In reply to

    Re: Using Xpath to display only the year?

    Hello, and welcome! First change your text box to contain text rather than a date, since we will only have part of the date in there.

    1. Right click your text box and select properties
    2. For Data Type, select Text(string)
    3. Select the formula button next to the Value box in the Default Value section
    4. Select Insert Function
    5. Select substring-before (in the Text functions)
    6. For the first field, put in the field with the date your want or the function today() for today's date
    7. After the comma, put in "-"

    Your final formula should look like this (if you are wanting the year for today's date):

    substring-before(today(), "-")

    Click OK until all dialogs close and open your form in preview to test.

    The substring-before function takes all the characters in the first string (today() in our case) up to the first occurance of the character in the second string (the hyphen, for us). Since today() returns a date formatted as: "2008-07-16", taking everything before the first hyphen returns the year.

    Let me know if you have trouble with this, okay?

    Hilary Stoupa

  • 07-17-2008 11:54 AM In reply to

    Re: Using Xpath to display only the year?

    If your dates are in the InfoPath standard format, you can use the text function substring-before. The date prints out yyyy-mm-dd in a text box.  The substring-before function will output all of the text before a certain character. The way to use it:

    substring-before(DateField, "-").  DateField is the field that has your date data.  The dash let's InfoPath know to stop at the dash and not add the month or day.

     

    Hope this helps,

     

     

    Ren

  • 07-17-2008 11:57 AM In reply to

    • jrudolph
    • Top 150 Contributor
      Male
    • Joined on 07-02-2008
    • Orlando, FL
    • Posts 67

    Re: Using Xpath to display only the year?

    Thank you very much.  That worked perfectly.  I need to spend some time and play with all these different functions.

  • 07-24-2008 02:20 AM In reply to

    Re: Using Xpath to display only the year?

    Wow, it works for me as well.

     thanks guys.

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