cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Super User
Super User

Patch Date to Azure SQL not working

SQL Date Column:

[date] DATE NOT NULL

Excerpt from PowerApps Patch command for date field:

date: Text(status_date.Text,"[$-en-US]yyyy-mm-dd")

Error:

This type of argument 'date' does not match the expected type 'Date'. 
Found type 'Text'.

What am I missing here? Per the SQL docs, a DATE-type column needs yyyy-mm-dd format. Thought that is what I was doing.

2 ACCEPTED SOLUTIONS

Accepted Solutions
Super User
Super User

Re: Patch Date to Azure SQL not working

@seadudeYou may try wrapping the Text() section in a DateValue(). Like this:

 

date: DateValue(Text(status_date.Text,"[$-en-US]yyyy-mm-dd"))

 *edit for typo*

View solution in original post

Super User
Super User

Re: Patch Date to Azure SQL not working

@seadudeI think the issue is that there isn't a statement in that Patch code for the base record to Patch, either a new one using Defaults('[dbo].[QSelf]') or an existing one using some filter like First(Filter('[dbo].[QSelf]', user=status_user.Text)).

 

If these are new records only, try:

 

Patch('[dbo].[QSelf]',
    Defaults('[dbo].[QSelf]'),
    {
     lat: status_lat.Text,
     long: status_long.Text,
     altitude: status_alt.Text,
     user: status_user.Text,
     notes: input_notes.Text,
     image: text_takenImage.Text,
     date: DateValue(Text(status_date.Text)),
     time: status_time.Text
    })

Otherwise, you will need to create the filter to edit the record you want like:

 

Patch('[dbo].[QSelf]',
    First(Filter('[dbo].[QSelf]', *your filter criteria here*)),
    {
     lat: status_lat.Text,
     long: status_long.Text,
     altitude: status_alt.Text,
     user: status_user.Text,
     notes: input_notes.Text,
     image: text_takenImage.Text,
     date: DateValue(Text(status_date.Text)),
     time: status_time.Text
    })

View solution in original post

5 REPLIES 5
Super User
Super User

Re: Patch Date to Azure SQL not working

@seadudeYou may try wrapping the Text() section in a DateValue(). Like this:

 

date: DateValue(Text(status_date.Text,"[$-en-US]yyyy-mm-dd"))

 *edit for typo*

View solution in original post

Super User
Super User

Re: Patch Date to Azure SQL not working

Nice work @wyotim! Thanks for the solution.

 

Interestingly, when I applied the `DateValue()` wrap, a different error popped up:

The first argument of 'Patch' should be a collection. 

Can I not patch directly to SQL? The table below, '[dbo].[QSelf]', shows up in intellisense and is definitely the name of the table in SQL. What gives?

 

Patch('[dbo].[QSelf]',
    {
     lat: status_lat.Text,
     long: status_long.Text,
     altitude: status_alt.Text,
     user: status_user.Text,
     notes: input_notes.Text,
     image: text_takenImage.Text,
     date: DateValue(Text(status_date.Text)),
     time: status_time.Text
    })
Super User
Super User

Re: Patch Date to Azure SQL not working

@seadudeI think the issue is that there isn't a statement in that Patch code for the base record to Patch, either a new one using Defaults('[dbo].[QSelf]') or an existing one using some filter like First(Filter('[dbo].[QSelf]', user=status_user.Text)).

 

If these are new records only, try:

 

Patch('[dbo].[QSelf]',
    Defaults('[dbo].[QSelf]'),
    {
     lat: status_lat.Text,
     long: status_long.Text,
     altitude: status_alt.Text,
     user: status_user.Text,
     notes: input_notes.Text,
     image: text_takenImage.Text,
     date: DateValue(Text(status_date.Text)),
     time: status_time.Text
    })

Otherwise, you will need to create the filter to edit the record you want like:

 

Patch('[dbo].[QSelf]',
    First(Filter('[dbo].[QSelf]', *your filter criteria here*)),
    {
     lat: status_lat.Text,
     long: status_long.Text,
     altitude: status_alt.Text,
     user: status_user.Text,
     notes: input_notes.Text,
     image: text_takenImage.Text,
     date: DateValue(Text(status_date.Text)),
     time: status_time.Text
    })

View solution in original post

Super User
Super User

Re: Patch Date to Azure SQL not working

You're exactly right. I was missing the (in my case) the Defaults line to tell PowerApps to create a new record in the table.

 

Thank you.

Super User
Super User

Re: Patch Date to Azure SQL not working

Happy that I could help!

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors
Users online (4,466)