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

Date/Time Add

Hello,

 

I am trying to figure out how to take a date/time item and add time to it. My Date/Time column from my SQL Table has the following format: 2019-10-22 21:52:43.000. In Power Apps it grabs it as 10/22/2019 9:52 PM

 

I would like to grab it as the way my SQL Table has it (same format) and be able to add 45 seconds to it.

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Microsoft RusselThomas
Microsoft

Re: Date/Time Add

Hi @mmattar ,

Is your SQL column a date formatted as text, or an actual datetime?

When rendering dates, it helps to understand the source type vs the display type.  It sometimes gets tricky using Text() to render datetimes as it has a source type of DATETIME but will result in a TEXT type output. 

In your formula, you're converting Parent.Default to DateTimeValue - the DateTimeValue function expects a text input.

Text(DateTimeValue(Parent.Default),DateTimeFormat.LongTime24)

So, is parent.default actually a string?

The reason it's important is that a source type of DATETIME can be rendered in many ways, but the data will always be the full datetime down to the millisecond.  You might only display the year, month, day or hours and minutes, but you can change your mind and display it down to the millisecond if you like because all the data is there.

When rendering off a TEXT type (a date formatted as text), then the only information available is what has already been rendered in text.  If the text only shows year/month/day then the rest will default to 00:00:00

In your case, I would expect the SQL data to be an actual DATETIME value, in which case you should be able to just do this;

Text(Parent.Default,"yyy-mm-dd hh:mm:ss")

 If it's actually a text type, and it has the seconds as you indicated in your original post, then this should work;

Text(DateTimeValue(Parent.Default),"yyy-mm-dd hh:mm:ss")

Included an example screenshot below - see the last one is a text conversion from the date you originally posted;

 

datetime.png

Hope this helps,

RT

View solution in original post

3 REPLIES 3
Highlighted
Microsoft RusselThomas
Microsoft

Re: Date/Time Add

Hi @mmattar ,

Check out the DateAdd() function;

DateAdd(yourdate, 45, Seconds)

Also check out the Text() and DateTimeValue() functions for changing the display format.

Hope this helps,

RT

mmattar
Level 8

Re: Date/Time Add

Hey i applied some of what you said and i got this far:

 

10/22/2019 9:52 PM is what i am getting from Power Apps, "Parent.Default", i apply this Text and DateTimeValue function on it Text(DateTimeValue(Parent.Default),DateTimeFormat.LongTime24) and get 21:52:00, but it is suppose to be 21:52:43. Why is it not counting the seconds, how can i grab those as well. 

 

Thanks

Microsoft RusselThomas
Microsoft

Re: Date/Time Add

Hi @mmattar ,

Is your SQL column a date formatted as text, or an actual datetime?

When rendering dates, it helps to understand the source type vs the display type.  It sometimes gets tricky using Text() to render datetimes as it has a source type of DATETIME but will result in a TEXT type output. 

In your formula, you're converting Parent.Default to DateTimeValue - the DateTimeValue function expects a text input.

Text(DateTimeValue(Parent.Default),DateTimeFormat.LongTime24)

So, is parent.default actually a string?

The reason it's important is that a source type of DATETIME can be rendered in many ways, but the data will always be the full datetime down to the millisecond.  You might only display the year, month, day or hours and minutes, but you can change your mind and display it down to the millisecond if you like because all the data is there.

When rendering off a TEXT type (a date formatted as text), then the only information available is what has already been rendered in text.  If the text only shows year/month/day then the rest will default to 00:00:00

In your case, I would expect the SQL data to be an actual DATETIME value, in which case you should be able to just do this;

Text(Parent.Default,"yyy-mm-dd hh:mm:ss")

 If it's actually a text type, and it has the seconds as you indicated in your original post, then this should work;

Text(DateTimeValue(Parent.Default),"yyy-mm-dd hh:mm:ss")

Included an example screenshot below - see the last one is a text conversion from the date you originally posted;

 

datetime.png

Hope this helps,

RT

View solution in original post

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

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
Users online (5,881)