Day of week from date picker - InfoPath Dev
in

InfoPath Dev

Day of week from date picker

Last post 12-28-2011 12:07 PM by Melli111. 11 replies.
Page 1 of 1 (12 items)
Sort Posts: Previous Next
  • 05-01-2008 10:58 AM

    Day of week from date picker

    My problem today is taking the date chosen from a date picker ("/dfs:myFields/my:Week/my:WeekBeginning") within infopath and finding the day of the week for that date.  I am using vb.net language(compatible with 2003).  I think it is a formatting of the xml date to the correct format for the weekday function.

     I have gotten this to work:

    Dim dt As New DateTime(2008, 5, 1)

    thisXDocument.DOM.selectSingleNode("/dfs:myFields/my:DayOfweek").text = dt.DayOfWeek

    That returns 4, then I can create a Case statement to check and enter the day.  My problem is that the day isn't always may 1st, 2008, it is selected from the date picker.  My ultimate goal is to verify that the day selected is a saturday, if not, show a message, and zero the date picker.

    I am just at a lost today with it, any help would be appreciated.

  • 05-05-2008 03:52 PM In reply to

    Re: Day of week from date picker

    You need to first get the text value of the date (forgive me if I write bad VB -- I'm not fluent in it):

    Dim dtString as New String
    dtString = thisXDocument.DOM.selectSingleNode("/dfs:myFields/my:WeekBeginning").text

    Dim dt As New DateTime
    dt = DateTime.Parse(dtString) ' Probably want to do some error checking here before you process the next line. Or you could use a try/catch statement.

    thisXDocument.DOM.selectSingleNode("/dfs:myFields/my:DayOfweek").text = dt.DayOfWeek

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

    Re: Day of week from date picker

    thanks!  that worked great.  I had a data type wrong, and now all is well.

  • 05-07-2008 04:31 PM In reply to

    Re: Day of week from date picker

    Great! Glad to hear it's working!

  • 11-23-2009 01:23 AM In reply to

    Re: Day of week from date picker

    It is possible codeless

     The previous reply gave a link to an already codeless way of doing it, using e secondary datasource, the next link gives another solution without secondary datasources (1 formula and rules)

    Have a look at http://blueinfopath.wordpress.com/2009/11/22/weekday-name-function-in-infopath/

     

    Frederik Van Lierde
    Blue InfoPath Blog  ¦  SilverSands Associate  ¦  Do you follow me already?  ¦  We work smart, not hard


    If this article was helpfull, don't forget to rate it, tnx!
  • 07-10-2010 03:59 AM In reply to

    Re: Day of week from date picker

    Hi Frederik,

    Thank a lot for your post. It's really very helpfull post.

    But some how i am getting error while using below formulas.

    1. Set Default Value of Field MyDay to normalize-space(substring-after(substring-after(../my:MyDate, “-”), “-”))
    2. Set Default Value of Field MyMonth to normalize-space(substring-before(substring-after(../my:MyDate, “-”), “-”))
    3. Set Default Value of Field MyYear to normalize-space(substring-before(../my:MyDate, “-”))

    I tried like this

    normalize-space(substring-after(substring-after(../my:MyDate, “-”), “-”))


    and

    (substring-after(substring-after(../my:MyDate, “-”), “-”))

    but i am getting error like

    (Unexpected character.
    (substring-after(substring-after(../my:MyDate, -->“<---”), “-”))
    )


    (Expected value type: end-of-string

    Actual value: name
    Unexpected -->character.
    <--(substring-after(substring-after(../my:MyDate, -->“<---”), “-”))
    )

    Could you Please help me how to use above formula. thanks for your help

    Thanks,

    Siva. 

     

     

     

     

  • 08-20-2010 07:08 AM In reply to

    Re: Day of week from date picker

    substitute the quotes and minus sign with the one on your keyboard.  Infopath does not like the way it is formated when you copy and paste from the Web page.  You have to delete the quotes and minus sign and re-type them.

     

    Mike

  • 08-20-2010 07:10 AM In reply to

    Re: Day of week from date picker

    Bad things about the rules above is that when you change the date for the first time it works but if you change again, lets say you first pick a Friday and then you want to pick a Thursday, nothing happens.  If you pick a date for the next month, it works.

  • 12-28-2011 11:31 AM In reply to

    Re: Day of week from date picker

    Hi Frederik,

    I know this post is old, but I'm hoping that you happen to have an updated URL to the link you posted in 2009?  I used the link about a year ago and it worked great, but now the blog has been deleted.  Unfortunately somehow my rules got deleted and I don't remember anything about how it was done. 

    Thanks in advance!

    Melissa

  • 12-28-2011 11:54 AM In reply to

    Re: Day of week from date picker

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 12-28-2011 12:07 PM In reply to

    Re: Day of week from date picker

    Thanks Jimmy!

    I actually had just found that shortly after I posted.  I put my own spin on it that mixed what was in the link I orginally used with the formula in the link you provided. 

    Instead of having the hidden sections show the day of week I just use conditional rules to set a field to the string of the day of the week. 

    If hiddenDayOfWeek = 1
    Action:  Set dayOfWeek = Monday

    I still had the rules set, I had just accidently deleted the rule that set the hiddenDayOfWeek to get the 0 - 6 value.  So, I just popped that formula in from bizsupportonline and everything worked again.  :)

    Adding a conditional rule for 0 - 6 (Sunday - Saturday)

    Thanks again Jimmy,

    Melissa

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