Skip to main content

Notifications

Power Apps - Building Power Apps
Unanswered

Date and Time in Patch and collect function

(0) ShareShare
ReportReport
Posted on by

Hi Experts,

I have date picker for date and for time I have used dropdowns. Now I need to send those data into collect and patch function 

Here my code-

date.PNG

What I was thinking is taking that date into label named dateandtime as shown in above image and sending that label into patch and collect function.

But how to pass it-

Can I use just dateandtime? It is not giving me error in patch function but in Collect it is throwing error. 

Tejasvi_munge_1-1593439940236.png

 

 

 

How can I date with time without error?

Any help is appreciated!

 

Categories:
  • wyotim Profile Picture
    wyotim 2,538 on at
    Re: Date and Time in Patch and collect function

    @Anonymous I found this forum post that will hopefully be of use to you. It looks like there is a different kind of syntax with the Two Option data type. Here is the way it was done in the solution post:

    // Their example:
    If(Toggle1.Value=true, 'IsOverdue (TaskLists)'.Yes, 'IsOverdue (TaskLists)'.No)
    
    // In general terms:
    If(Toggle1.Value=true, 'FieldName (EntityName)'.TrueValue, 'FieldName (EntityName)'.FalseValue)


    Again, being a SQL guy, this is a bit out of my expertise but, hopefully, this example and that forum post get you where you need to be! 

  • Re: Date and Time in Patch and collect function

    Hi @wyotim ,

    Thanks for the response.

    I have tried that already not working. Even I tried using variable. Any other thing which I can try?  

  • wyotim Profile Picture
    wyotim 2,538 on at
    Re: Date and Time in Patch and collect function

    @Anonymous Unfortunately, I don't have much experience at all with CDS; the company I work for primarily uses Azure SQL.

     

    I was able to find a blog post that referred to the Two Option data type. While it seems to work similar to a boolean field, it looks like it needs the actual item value used in CDS. Here is a link to that article. The relevant info I was looking at is under the heading "Writing Changes", near the bottom of that section. This article is from 2018 and about an experimental feature that doesn't seem to exist now, so I am assuming it was rolled out. 

     

    So instead of 'Toggle1.Value', maybe having a statement like:

    If(
     Toggle1.Value = true,
     TrueItem,
     FalseItem
    )

    where TrueItem and FalseItem are the actual values for the Two Option data. 

    If that doesn't work, we may need to track down someone with more CDS experience than me to help with that part. Let me know how it goes and we'll proceed from there!

  • Re: Date and Time in Patch and collect function

    HI @wyotim ,

    Sure will try. Also, I have toggle buttons here in powerapps which has "two options " datatypes in CDS entity. How can I use that in collect. I have used Toggle1.Value but it throws error saying invalid argument in collect. How can i do that?

     

  • wyotim Profile Picture
    wyotim 2,538 on at
    Re: Date and Time in Patch and collect function

    @Anonymous Rather than making a new label that holds that formula, you should actually put the formula in your Patch and Collect statements where the reference for that label is. So, where you currently have 'Journeydateandtime' in those formulas, put:

    DateTimeValue(Substitute(Dateandtime.Text, "Time", ""))})


    I hope that makes sense. Basically, you don't need to have another label; you can reference the one you already have and let the formula above take care of the formatting. Let me know if that does what you need or not!

  • Re: Date and Time in Patch and collect function

    Hi @wyotim ,
    Thanks for the response!
    My data source needs it to be date an time value so it won't text. I have tried second approach- created one label as shown below

    Tejasvi_munge_0-1593491800349.png

    but it is not working in collect function

    Tejasvi_munge_1-1593491946955.png

    Am I missing anything?

     

     

  • wyotim Profile Picture
    wyotim 2,538 on at
    Re: Date and Time in Patch and collect function

    Hey @Anonymous, I think one issue might be that you seem to be missing the ".Text" portion on the Dateandtime reference. Essentially, it is referencing the control itself and not the text value of the control. So it should probably be:

    ... journeystartdateandtime: Dateandtime.Text});
    ...

     

    This is assuming that your data source will take this value as text and doesn't need it to be an actual datetime value. There will likely be an error saying it was expecting a datetime value but received a text value if that is the case. If it needs to be a datetime value, you would probably need to remove the "Time" text from the front and format the resulting text as datetime. Here is one way you could do that:

    ... journeystartdateandtime: DateTimeValue(Substitute(Label1.Text, "Time", ""))});
    ...

     

    Basically, the substitute function replaces the text "Time" with nothing (""), and the DateTimeValue function formats the rest as a datetime value (unsurprisingly). 

     

    Hopefully, that helps! Let me know if it does or doesn't sort things out; I'm happy to follow up if needed!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,304

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,703

Leaderboard