cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
seadude
Memorable Member
Memorable Member

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
wyotim
Resident Rockstar
Resident Rockstar

@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

wyotim
Resident Rockstar
Resident Rockstar

@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
wyotim
Resident Rockstar
Resident Rockstar

@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*

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
Resident Rockstar
Resident Rockstar

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

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
Resident Rockstar
Resident Rockstar

Happy that I could help!

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (5,741)