Calculate previous month - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Calculate previous month

Last post 02-22-2011 05:04 PM by Vanessa Larsen. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 02-21-2011 10:57 PM

    Calculate previous month

    Hi all,

    I'm currently developing a (InfoPath 2010) form where there is the requirement to automatically populate the field with the previous month e.g. January 2011. I know that an easy way to calculate this would be to use today()-30, however this doesn't cater for months where there are 31 days - and the users typically submit these forms at the end of the month.

    I was hoping someone would know of a smarter (code-free) way to calculate the previous month?

    Cheers,

    Vanessa

    Blog: http://www.myriadtech.com.au/blog/Vanessa
  • 02-21-2011 11:11 PM In reply to

    Re: Calculate previous month

    Rule:

    Condition: substring(today(), 6, 2) = 1

    Year = substring(today(), 1, 4) - 1

    Month = 12

    Condition: substring(today(), 6, 2) != 1

    Year = substring(today(), 1, 4)

    Month = substring(today(), 6, 2) - 1

    Or without conditions:

    Year = substring(today(), 1, 4) - (substring(today(), 6, 2) = 1)

    Month = substring(today(), 6, 2) - 1 + 12 * (substring(today(), 6, 2) = 1)

     

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 02-22-2011 05:04 PM In reply to

    Re: Calculate previous month

    Awesome, thanks so much for your help :-)

    Blog: http://www.myriadtech.com.au/blog/Vanessa
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.