Date Format - InfoPath Dev
in

InfoPath Dev

Date Format

Last post 09-21-2009 05:14 PM by Jimmy. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 09-20-2009 06:31 PM

    Date Format

    Hi i have successfully used the XSLT method to create a form that when submitted sends field data to a word doc with a predefined template. I have the majority of data coming across as desired however I need to iron out a few issues.

    I have 2 date fields in the form that when submitted to ms word read YYYY-MM-DD. I need the format to be DD-MMMM-YYYY ie 20-September-2009. Does any one know how to achieve this. When I look at one of the dates in the xsl file it reads as follows:

    <xsl:apply-templates select="ns2:Date" />

    Is there anyway of achieving what I desire here?

    Cheers 

     

    Filed under: , ,
  • 09-20-2009 08:45 PM In reply to

     There is most likely a way to do this.  Would you mind sharing your XSLT with us so it would be a bit easier to help?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 09-20-2009 10:00 PM In reply to

    I have attached very basic duplicate of my xslt due to privacy I cannot send the original. Thank you

  • 09-20-2009 10:03 PM In reply to

    <xsl:apply-templates select="ns1:Birth" />

    <xsl:apply-templates select="ns1:Date" />

    are the fields I am looking to have formatted 


     

     

  • 09-21-2009 12:55 AM In reply to

     Thanks.  The attached file should give you an idea of how to do it.

    What I did:

    • Add the msxsl namespace declaration to the <xsl:stylesheet> node at the top of the file.
    • Add a new template called "formatDate" near the end of the file:
          <xsl:template name="formatDate">
              <xsl:param name="date" />
              <xsl:variable name="months">
                  <Month>January</Month>
                  <Month>February</Month>
                  <Month>March</Month>
                  <Month>April</Month>
                  <Month>May</Month>
                  <Month>June</Month>
                  <Month>July</Month>
                  <Month>August</Month>
                  <Month>September</Month>
                  <Month>October</Month>
                  <Month>November</Month>
                  <Month>December</Month>
              </xsl:variable>
              <xsl:value-of select="concat(substring($date, 9, 2), '-', msxsl:node-set($months)/Month[position() = substring($date, 6, 2)], '-', substring($date, 1, 4))"/>
          </xsl:template>
    • Replace <xsl:value-of select='.' /> with
                  <xsl:call-template name="formatDate">
                      <xsl:with-param name="date" select="." />
                  </xsl:call-template>
      in the places where my:Date and my:Birth are placed into the word formatting.
    Hopefully that will do the trick for you.
    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 09-21-2009 03:42 PM In reply to

    Jimmy you are my hero!!Works a treat. Thankyou so much!!

    I am new to this site is there a rating system where mark you as helpful or give you some recognition for your services.

     

  • 09-21-2009 04:45 PM In reply to

    Hi Again, can you have a look at the attached file and let me know what I am doing wrong I have tried to perform the same process on this file but the date formats are not changing. I apologise I am not a programmer so I may have made an obvious mistake.

    Date fields in this file are "Expiry" and "Date"

    Never mind I fixed it :)

  • 09-21-2009 05:14 PM In reply to

    LowRyda:

    I am new to this site is there a rating system where mark you as helpful or give you some recognition for your services.

     

     Not that I know of, but your thanks in this thread are recognition enough. :-)

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
Page 1 of 1 (8 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.