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

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
Highlighted
Power Apps
Power Apps

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
Highlighted
Power Apps
Power Apps

Re: Date Control

The DatePIcker control can only do dates, not times.

Highlighted
Post Patron
Post Patron

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?

Highlighted
Community Support
Community Support

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.
Highlighted
Post Patron
Post Patron

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?

 

Highlighted
Power Apps
Power Apps

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.

Highlighted
Post Patron
Post Patron

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)

Highlighted
Power Apps
Power Apps

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

Highlighted
Post Patron
Post Patron

Re: Date Control

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

Highlighted
Post Patron
Post Patron

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
Community Conference

Power Platform Community Conference

Find your favorite faces from the community presenting at the Power Platform Community Conference!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (12,203)