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

Date Control

Am I able to have both date and time using the Date Picker control? Or is that function only available when using an edit or display form?

1 ACCEPTED SOLUTION

Accepted Solutions
PowerApps Staff AndyPennell
PowerApps Staff

Re: Date Control

DateTimes are stored in SQL in UTC (for obvious reasons). By default PA will display them / parse them in local time. You can display them in UTC by using "utc" as the format string.

View solution in original post

9 REPLIES 9
PowerApps Staff AndyPennell
PowerApps Staff

Re: Date Control

The DatePIcker control can only do dates, not times.

Re: Date Control

Shucks.  I will have to concatenate the Date Picker and an input box as one value. Is there a formula that would be able convert that data into a datetime format that can be read by SQL?

Community Support Team
Community Support Team

Re: Date Control

Hi @BrendonBrooksP1,

 

See the following article:

Show text and format dates and times in PowerApps

DateValue,TimeValue, and DateTimeValue functions in PowerApps

The DateTimeValue function should be able to convert the string into datetime format.

Regards

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Re: Date Control

The examples given in the Date Time Value page only references display DTV on a label. That function works fine.

 

However, when Patching to a SQL table, where the format for the column is set to DATETIME,  I receive an error.  I'm using this formula:

 

Patch('[dbo].[table1]', Defaults('[dbo].[table1]'),{ StartDate: Text(DateValue(StartDateTime.Text))})

 

Since it's not possible to Patch a text Label, my current options are to set the StartDate column in the SQL table to NVARCHAR(50).  Am I missing something here? Is there a way to Patch a DTV input into a SQL table?

 

PowerApps Staff AndyPennell
PowerApps Staff

Re: Date Control

Is StartDate the SQL column? If so then dont use the Text function (which will convert to string) - DateValue will suffice, it returns the correct type and the SQL connector should be able to patch it.

Re: Date Control

Andy,

 

Yes, StartDate is the SQL column.  I used the following and it worked, with one minor issue. When I input the following date and time,  04/21/2017 11:00 AM, the SQL column will display a date and time of 04/21/2017 06:00 PM.  Is there an additional option or formula that ensures that the local time zone is being inputed into the SQL table?

 

Here's the formula that I used:

 

 

StartDate: DateTimeValue(FlightStart.Text)

PowerApps Staff AndyPennell
PowerApps Staff

Re: Date Control

DateTimes are stored in SQL in UTC (for obvious reasons). By default PA will display them / parse them in local time. You can display them in UTC by using "utc" as the format string.

View solution in original post

Re: Date Control

Very well. Good to know! Thank you for your help.

Re: Date Control

Okay, this is really strange.  So I implemented the solution that was in this thread. But upon looking at my SQL database, I have one column (set to DateTime in SQL) that displays time in UTC while the other one (set to DateTime in SQL) will actually input the local time that I typed in the text input box. For reference, here is the formula that I'm using for both columns:

 

Patch('[dbo].[FlightLog]', Defaults('[dbo].[FlightLog]'), {StartDate: DateTimeValue(FlightStart.Text), EndDate: DateTimeValue(FlightEnd.Text)})

 

Once again, both text inputs will successfully Patch to the SQL table, but time zones are way off.  I've attached some photos for reference. Please take note that the dates on there that are from 2016 to January 2017 are imported records.

 

 

 

RECORDS.PNGtime.PNG

 

 

 

 

 

 

Helpful resources

Announcements
thirdimage

Power Automate 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

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (4,969)