cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SeanTambling
Level: Powered On

Can't get date to reflect correctly in power app

I've got a gallery screen that is filtered to show contents of a small SQL table. One of the fields in the table is a date selector. A user navigates to the screen after selecting a group. The gallery displays a date selector and a comments field and has a save/submit button to patch the SQL data base if there is a change in the date or comments field. The date selector is updating a date field in the SQL table. I have populated some of the table with test data. When the gallery loads and you see the date field, it shows the date as 1 day less than what is in the table. If you change the date in one of the other items in the gallery, you can select what ever date you want ,but once you press the save/submit button the table is patched and the gallery refreshes and the date changes to 1 day less than what you selected. If you check the data in the table with an infopath form, you see the correct date you chose. So, while it is updating the table correctly, it displays wrong in the powerapp. What am I doing wrong? This shouldn't be this hard.

 

I'm attaching some images of the gallery item. It does the same thing regardless of which item you're changing.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: Can't get date to reflect correctly in power app

I created an app a while ago that display dates in a Data Picker field from a SQL Database table.

Demo: https://youtu.be/KwHTVjL_LBU

 

It took me quite a while to get the date value dispaying the correct info, especially pertaining to get the correct information displaying regardless of the timezone the app had been launched in.

 

Looking back now at the source code in that app for the Date Picker control I specified the following property values that collectively displayed the correct info across different time zones:

 

DateTimeZoneDateTimeZone.UTC

DefaultDate: If( IsBlank( activity_date_v ), DateAdd( Now(), - TimeZoneOffset(), Minutes ), attendance_date_v )

 

When editing an existing record the activity_date_v variable is set to the specific date saved in the SQL table, passed to the Add/Edit Form screen from the selected item gallery control in the preceeding screen in the app.

 

When adding a new record, obviously the default value for the Date Picker control is determed by the DefaultDate property, however what I can't exactly recall why (albeit that it must have been relevant), in the OnSelect property of the Date Picker control contains the following code:

 

If( DateDiff(
        Activity_Date.SelectedDate;
        attendance_date_v,
        Days
) <> 0,
    UpdateContext({ attendance_date_v: Activity_Date.SelectedDate })
);
UpdateContext({
    attendance_date_v:
        If( DateDiff(
            Activity_Date.SelectedDate,
            DateAdd( Now(), -TimeZoneOffset(), Minutes ),
            Days
        ) < 0,
        DateAdd( Now(), -TimeZoneOffset(), Minutes ),
        Activity_Date.SelectedDate
        )

    }

)

 

Interestingly although I used the Patch function to add a new record, I don't use the attendance_date_v variable in the Patch statement. Instead I use the following code:

 

Patch( '[dbo].[ActivityAttendance]',
    Defaults( '[dbo].[ActivityAttendance]' ),
    { activitydate: Activity_Date.SelectedDate, 
      userpresent: Activity_User.Id,
      capturedbyid: loggedin_user_v.id,
      captureddate: Now(),
      modifiedbyid: loggedin_user_v.id,
      modifieddate: Now()
    }
)

 

Collectively that code definely worked for the app I created at least...

View solution in original post

5 REPLIES 5
AnneZC
Level: Powered On

Re: Can't get date to reflect correctly in power app

Hi @SeanTambling 

It sounds like a Time Zone issue. What time zone are you in and do you know what Time Zone your 
Office 365 Tenant is in?

SeanTambling
Level: Powered On

Re: Can't get date to reflect correctly in power app

How do I locate the timezone info?

SeanTambling
Level: Powered On

Re: Can't get date to reflect correctly in power app

@AnneZC ,

I've been looking since you replied to me yesterday for where to view the tenant time zone, and possibly change it, but I've not found it yet.

 

I'm not really sure why this would be the problem though, i don't have this problem with another app that has dates in it, so i'm confused why this one would be having this issue. The other app I'm referring to with dates in it, is a canvas app that uses SPO for the data. The app I am having the issue with dates is using SQL for the data source.

Any help would be greatly appreciated. 

Highlighted

Re: Can't get date to reflect correctly in power app

I created an app a while ago that display dates in a Data Picker field from a SQL Database table.

Demo: https://youtu.be/KwHTVjL_LBU

 

It took me quite a while to get the date value dispaying the correct info, especially pertaining to get the correct information displaying regardless of the timezone the app had been launched in.

 

Looking back now at the source code in that app for the Date Picker control I specified the following property values that collectively displayed the correct info across different time zones:

 

DateTimeZoneDateTimeZone.UTC

DefaultDate: If( IsBlank( activity_date_v ), DateAdd( Now(), - TimeZoneOffset(), Minutes ), attendance_date_v )

 

When editing an existing record the activity_date_v variable is set to the specific date saved in the SQL table, passed to the Add/Edit Form screen from the selected item gallery control in the preceeding screen in the app.

 

When adding a new record, obviously the default value for the Date Picker control is determed by the DefaultDate property, however what I can't exactly recall why (albeit that it must have been relevant), in the OnSelect property of the Date Picker control contains the following code:

 

If( DateDiff(
        Activity_Date.SelectedDate;
        attendance_date_v,
        Days
) <> 0,
    UpdateContext({ attendance_date_v: Activity_Date.SelectedDate })
);
UpdateContext({
    attendance_date_v:
        If( DateDiff(
            Activity_Date.SelectedDate,
            DateAdd( Now(), -TimeZoneOffset(), Minutes ),
            Days
        ) < 0,
        DateAdd( Now(), -TimeZoneOffset(), Minutes ),
        Activity_Date.SelectedDate
        )

    }

)

 

Interestingly although I used the Patch function to add a new record, I don't use the attendance_date_v variable in the Patch statement. Instead I use the following code:

 

Patch( '[dbo].[ActivityAttendance]',
    Defaults( '[dbo].[ActivityAttendance]' ),
    { activitydate: Activity_Date.SelectedDate, 
      userpresent: Activity_User.Id,
      capturedbyid: loggedin_user_v.id,
      captureddate: Now(),
      modifiedbyid: loggedin_user_v.id,
      modifieddate: Now()
    }
)

 

Collectively that code definely worked for the app I created at least...

View solution in original post

SeanTambling
Level: Powered On

Re: Can't get date to reflect correctly in power app

So after a lot of playing around with the datepicker control, I'm still having trouble getting everything to work just right.

 

I have changed the DateTimeZone to UTC.

The Default date is ThisItem.StageDate

EndYear is 2050

Format is ShortDate

InputTextPlaceholder is Text(Date(2001,12,31), StageDateDatePicker.Format, StageDateDatePicker.Language)

IsEditable is false

Language is blank

Onchange is UpdateContext({VisibleVar:true})

Onselect is blank

Reset is false

Start of week is Sunday

Start year is 1970

Visible is true

 

My problem is that when i select a date from the datepicker calendar and then press the save/submit button the date changes on refresh to 1 day less than what was selected. When i look at the data in the SQL data base it reflects the same problem. I can't figure out why i'm having this problem. It seems like a bug, but IDK. 

 

The patch function for the save/submit button is: Patch('[dbo].[tblPipelineStages]', ThisItem, {StageDate: StageDateDatePicker.SelectedDate}, {Comments: StageCommentsInput.Text});Refresh('[dbo].[tblPipelineStages]');UpdateContext({VisibleVar:false})

 

The datepicker, comments input, and save/submit button are all controls inside of a gallery.

 

I've attached an image of one of the gallery items to show what it looks like

 

Any ideas why the date picker would be sending the wrong date the the SQL table?

 

All help appreciated.

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

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 (Last 30 Days)
Users online (4,614)