Converting date-time to date - InfoPath Dev
in

InfoPath Dev

Converting date-time to date

Last post 06-12-2007 08:19 AM by davidair. 11 replies.
Page 1 of 1 (12 items)
Sort Posts: Previous Next
  • 06-11-2007 07:41 AM

    Converting date-time to date

    Hi. I am using infopath forms to query sharepoint. And one of field in the form it gets a date from sharepoint list coulomb which is a date picker but on the form it shows like " 2007-06-20 00:00:00 " but i want it to show like " 06/20/2007 "

    i tryied to set up function on the rules but i doesnt work. so how can i convert this date?

  • 06-11-2007 08:52 AM In reply to

    Re: Converting date-time to date

    Data formatting is your friend here...

    - Double-click on your control (whether it's a data picker or a textbox, does not matter)

    - Click on the "Format" button

    You should see two sections, one for date and one for time. Make sure "(Do not display time)" is selected in the second section.

    Disclaimer: I have only tried this in InfoPath 2007 although a similar functionality should be available in IP2003 as well.

    I hope this answers your question...

    Good luck!

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-11-2007 08:59 AM In reply to

    Re: Converting date-time to date

    thx for answer. i am using sp2007 too. i tried this before. i did not work.
  • 06-11-2007 09:12 AM In reply to

    Re: Converting date-time to date

    So were you able to get it to work this time around? If not, could you give more details of what you are doing and it is breaking?
    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-11-2007 09:40 AM In reply to

    Re: Converting date-time to date

    I tried this

     
      Public Shared Function Mid(ByVal str As String, ByVal Start As Integer, Optional ByVal Length As Integer) As String
            Public Sub inspdate1_Validating(ByVal sender As Object, ByVal e As XmlValidatingEventArgs)
                ' Write your code here.


                Dim newDT As String
                Dim DT As String
                Dim inspdate1 As String

                inspdate1 = "/my:myFields/my:inspdate1"
                DT = inspdate1
                newDT = Mid(DT, 6, 2) + "/" + Mid(DT, 9, 2) + "/" + Mid(DT, 1, 4)
                inspdate1 = newDT


            End Sub

     

    but it put underlines the letter (bracket in the first line ) which i made bold here. and says  -- optional parameters must specify a default value--

  • 06-11-2007 10:08 AM In reply to

    Re: Converting date-time to date

    Well, there are several problems with this code:

    - inspdate1 would not be defined - it's a name of a data field. Typically you have to select the XPathNavigator corresponding to your data field from the DOM you're interested in. In this case, however, the navigator is available as e.Site: you get the value as e.Site.Value and you set it via e.Site.SetValue

    - I don't believe you can change the value of the field in its Validating event - during this event the field is read-only

    - Changing the value of the field in its OnChange event is likely to cause an infinite loop: OnChange fires, you change the value, OnChange fires again

    - I don't know the details on Mid but what happens if DT is empty?

    I would avoid writing any code unless you really have to. Do you want to change the data or the way it's displayed? If it's the later, then Formatting is really what you need.

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-11-2007 10:32 AM In reply to

    Re: Converting date-time to date

    but i tried all of the formatting options but nothing happens. it continues to show date like 2007-01-01 00:00:00 i search net and saw not only me has this problem. and there is no solution with infopath interface i think. by the way DT will be never empty in our database.

    Or the solution is changing all date time pickers to normal textboxes in sharepoint. 

  • 06-12-2007 07:28 AM In reply to

    Re: Converting date-time to date

    Interesting... I would like to take a look at your Solution, do you think you could share out our XSN? You can attach files in the Files section on the forum...
    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-12-2007 07:48 AM In reply to

    Re: Converting date-time to date

    ok i uploaded it. as you see there is two date section. the first one put the today's but the second one Observation date gets date information from a shareopint list.
  • 06-12-2007 08:01 AM In reply to

    Re: Converting date-time to date

    Hmm... since I am not seeing the data I cannot say what is going wrong. One guess is maybe you should try to change the underlying data type of DateOfInspection to DateTime from Date, and then you can tell it not to display time. If that does not work I don't know what will :)

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-12-2007 08:15 AM In reply to

    Re: Converting date-time to date

    i tried this too. and finally i think there is two solution.

    1- i have to change all fields which are date time picker to textboxes.

    2- The date seems 2007-01-01 00:00:00. After sharepoint query and put the date on the textbox if you delete the time part which is 00:00:00 manualy it converts to date 01/01/2007 automatically.

    i am thinking to use second solution. Thanks for your help. 

  • 06-12-2007 08:19 AM In reply to

    Re: Converting date-time to date

    Cool, good luck!
    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
Page 1 of 1 (12 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.