cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
seadude
Level 8

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.


Accepted Solutions
wyotim
Level 8

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*

wyotim
Level 8

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
    })

All Replies
wyotim
Level 8

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*

seadude
Level 8

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
    })
wyotim
Level 8

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
    })
seadude
Level 8

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.

wyotim
Level 8

Re: Patch Date to Azure SQL not working

Happy that I could help!