Displaying the month in an InfoPath form


Someone asked this question on a discussion list and I thought the answer was one that others might be interested in.

What do you do if you want to set a field in an InfoPath form to show the month that the form is filled out?

This can be done by using the today() function. This function returns the date of the day that the function is called on. For example, if you call it on the 1st of March, it will return the value 2012-03-01 (you can change the way this is displayed, but this is the value pulled back by the function).

If you want to just display the month, rather than the full date, you can expand the formula using the substring function. This is a little function that takes a string and returns just a piece of it. So the function substring(today(), 6, 2) would return two characters of the string “2012-03-01”, starting with the sixth character. In this example, you’d get 03.

So that gives you the value for the month, but what if you want to see the text?

This requires another rule or, more accurately, twelve of them. Have a rule that looks at the value brought back by the previous formula and if it equals “01”, set the value of the month field to “January” and so on for the other eleven months.   

It’s probably easier to keep these two pieces slightly separate, rather than trying to do everything in one set. For example, you can have a field called month_value which is not displayed on the form. Create the first rule to populate this with the value substring(today(), 6, 2). This rule could be attached to form load behaviour, a button, another field, the submit action or various other items. However you choose to trigger it, it will populate this field with the number of the month.

Then you should have a second field, which is used to display the month name in the form. On this field, add the twelve rules to set the value of the field based on the value in month_value. You may want to set another condition that only does this if the month field is blank.

And make sure to make this field read-only otherwise someone will type something in and wreck your lovely rules.

Comments (3)

  1. wewerer says:

    https://www.facebook.com/WatchAmericanUltraOnline
    https://www.rebelmouse.com/WatchAmericanUltraOnline/
    https://www.rebelmouse.com/WatchWarRoomOnline/
    https://www.linkedin.com/grp/post/6973703-6017389460872769538
    https://www.facebook.com/WatchJaneGotaGunOnline
    https://www.rebelmouse.com/WatchPixelsOnline/
    https://www.rebelmouse.com/WatchTheManFromUncleOnline/
    https://www.linkedin.com/grp/post/8337129-6017929104496558084
    https://www.linkedin.com/grp/post/6986867-6032768460054876161
    https://www.linkedin.com/grp/post/6986867-6032769411218161668
    http://www.screencast.com/t/wLvCIalkv7jH
    https://www.rebelmouse.com/WatchTheVisitOnline/
    https://www.linkedin.com/grp/post/8338032-6017239480027664385
    http://www.screencast.com/t/4dIdLNwrwd
    https://www.rebelmouse.com/WatchRickiAndTheFlashOnline/
    https://www.linkedin.com/grp/post/6975089-6015035619363807236
    https://www.linkedin.com/grp/post/6980115-6017745897104883716
    https://www.linkedin.com/grp/post/6981021-6017297880677638145
    https://www.facebook.com/WatchHotelTransylvania2OnlineNow
    https://www.linkedin.com/grp/post/8338032-6017247400261926914
    https://www.linkedin.com/grp/post/6986867-6032763607513575428
    https://www.rebelmouse.com/watchthewalkonline/
    https://www.rebelmouse.com/WatchSouthpawOnline/
    http://www.screencast.com/t/IXgnchZvJ5Qi
    https://www.rebelmouse.com/MazeRunner2TheScorchTrials/
    http://www.screencast.com/t/Z3ia9z8bNm
    https://www.rebelmouse.com/WatchEverestOnline/
    https://www.facebook.com/WatchMagicMikeXXLOnline
    https://www.linkedin.com/grp/post/6971553-6011498080841510914
    https://www.rebelmouse.com/WatchSelflessOnline/
    http://www.screencast.com/t/sd6SU3y6X
    https://www.facebook.com/WatchRickiAndTheFlashOnline
    http://www.screencast.com/t/BqDYRnTTcd
    https://www.facebook.com/WatchPixelsOnline
    http://www.screencast.com/t/kwDvncnb7w
    https://www.linkedin.com/grp/post/6980115-6017741490241941507
    https://www.linkedin.com/grp/post/6981021-6017330014037491716
    http://www.screencast.com/t/2M47h34Ecs
    https://www.rebelmouse.com/MissionImpossible5RogueNation/
    https://www.rebelmouse.com/WatchMagicMikeXXLOnline/
    https://www.facebook.com/WatchMissionImpossible5RogueNationOnline
    https://www.linkedin.com/grp/post/6986867-6032761446725599232
    http://www.screencast.com/t/gAX1ovxR9Z
    https://www.rebelmouse.com/watchthemartianonline/
    https://www.rebelmouse.com/watchbeforeiwakeonline/
    https://www.linkedin.com/grp/post/6975089-6015034074878468096
    https://www.facebook.com/WatchFantasticFourOnline
    https://www.linkedin.com/grp/post/6986867-6032759905176276993
    https://www.linkedin.com/grp/post/8337129-6017929691594260480
    https://www.facebook.com/WatchTheVisitOnline

  2. weewrewrr says:

    http://www.screencast.com/t/T53l0HwY
    https://www.facebook.com/1496455867343036
    https://www.facebook.com/1488494651473391
    https://www.facebook.com/1485709085087347
    https://www.pinterest.com/pin/503840277041035513/
    https://www.facebook.com/1492982074353465
    https://www.pinterest.com/pin/503840277041036412/
    https://www.facebook.com/1493395824312090
    https://www.facebook.com/1488505948138928
    https://www.facebook.com/1493879734267173
    http://www.screencast.com/t/IpSAdwtHsvlz
    https://www.facebook.com/1487871671535689
    https://www.facebook.com/1494554237533056
    https://www.facebook.com/1493416294310043
    https://www.pinterest.com/pin/19421842120362656/
    https://www.facebook.com/1487838031539053
    https://www.facebook.com/1493432030975136
    https://www.pinterest.com/pin/160511174196348019/
    http://www.screencast.com/t/IPp2CXt6AOzK
    https://www.pinterest.com/pin/50665564535279371/
    https://www.facebook.com/1491434031175756
    https://www.pinterest.com/pin/50665564535279420/
    https://www.facebook.com/1491444347841391
    http://www.screencast.com/t/7Ym3MRr7y
    https://www.facebook.com/1493124021005937
    https://www.pinterest.com/pin/148478118942137282/
    http://www.screencast.com/t/WxwnarTs
    http://www.screencast.com/t/iKq3VX3Yfz
    https://www.pinterest.com/pin/148478118942137301/
    https://www.pinterest.com/pin/442830575838892619/
    http://www.screencast.com/t/DxIk45sk
    https://www.pinterest.com/pin/19421842120361786/
    https://www.facebook.com/1493817790940034
    https://www.facebook.com/1493394017645604
    https://www.pinterest.com/pin/350647520966521281/
    https://www.pinterest.com/pin/50665564535279042/
    https://www.pinterest.com/pin/19421842120367867/
    https://www.pinterest.com/pin/19421842120367516/
    https://www.pinterest.com/pin/503840277041036081/
    http://www.screencast.com/t/mN6wrTupTmf
    http://www.screencast.com/t/3qBTI1UhP
    http://www.screencast.com/t/xPQERxe7OOq
    https://www.pinterest.com/pin/160511174196348381/
    https://www.pinterest.com/pin/503840277041062631/
    http://www.screencast.com/t/dPkF0eWXA
    https://www.facebook.com/1483751835280749
    http://www.screencast.com/t/SMlp1Ccxm
    https://www.pinterest.com/pin/19421842120361889/
    https://www.pinterest.com/pin/50665564535278743/
    https://www.facebook.com/1491486697837156