cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
akbarmahfuzalam
Post Prodigy
Post Prodigy

Date and Time

Hello Team,

I'm stuck here and need aid from the community.

I have three text fields: StartTime, EndTime, and TotalTimeSpend.

I'm referring to form as form1.

When I select the status field as Production, Break, or any entry, I want the Starttime to take the current date and time, and when I submitform(form1), it should get the End date and time, as well as the total time spent in HH:MM:SS:

 

Starttime= DataCardValue5

Endtime = DataCardValue6

TotalTimeSpend= DataCardValue7

 

Data is storing in Sharepoint List name TimeTracker.

akbarmahfuzalam_1-1641839483971.png

 

 

akbarmahfuzalam_0-1641839071933.png

 

 

14 REPLIES 14
RandyHayes
Super User
Super User

@akbarmahfuzalam 

When you reference a Time function in your formula, it is evaluated when it first appears.  It will not update itself as the time changes.  So, you will need to keep track of the time in your app.

 

The best way to go about that is to place a Timer control in your app and set it not visible.  Set the AutoStart to true and the repeat to true and the duration to 1000.

In the OnTimerEnd action of the timer, place the following formula:  Set(glbCurrentTime, Now())

 

Now, in your formulas that you want to be based on current time, use the above variable instead of Now().

So, for your default formula, set it just to glbCurrentTime

 

By the way - Now() returns the date and time, so there is no need to do Today() + a time conversion based on the Hour minute and second, like you showed in your formula.  Now() is equivalent.  And with the above formula, glbCurrentTime is always Now() accurately updating.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

@RandyHayes 

Thanks a ton

Its working for StartTime but what do i need to put on EndTime and when i click the Save button it should store the date and time too. How its going to capture the time diff in the TotalTimeSpend

 

akbarmahfuzalam_0-1641840340694.png

 

RandyHayes
Super User
Super User

@akbarmahfuzalam 

Well, the rest of it is all logic in your form.

 

For example, I am going to only assume that the Start time only gets filled in if the Production status is chosen.  But, then you have a break time status and then what happens?  

Are you creating individual records for each action (production, break, end, etc)?  Or are you updating ONE record as the status changes?  If that is the case, then you need logic in the form to preserve start time once entered, and then how does break time get accounted for?

If you are doing an individual record for each action, then the calculation would be based on the StartTime and the EndTime only.

So, not sure what your logic is in the app.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

@RandyHayes 

Creating an individual records for each action (production, break, end, etc)?  Yes am updating ONE record as the status changes.  that is the case and i need logic in the form to preserve start time once entered.

Doing an individual record for each action, the calculation would be based on the StartTime and the EndTime only.

Now what would be the logic here.

 

RandyHayes
Super User
Super User

@akbarmahfuzalam 

So your default for the StartTime would be (note, since you're storing as text, we need to convert for it):

Coalesce(Parent.Default, Text(glbCurrentTime))

 

That will preserve the start time. 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

@RandyHayes 

StartTime sorted

Endtime____ ?
TotalTimeSpend___ ?

Save button___ ?

RandyHayes
Super User
Super User

@akbarmahfuzalam 

What triggers an End time?  I believe that is where the issue comes in.  

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

@RandyHayes 

 

When I click the Save button then only the EndTime trigger and the totaltimespend will trigger. And then form need to be reset for new entry

RandyHayes
Super User
Super User

@akbarmahfuzalam 

So if EndTime is getting set on save, then just set the Default of the End time to be the same as the starttime.

Coalesce(Parent.Default, Text(glbCurrentTime))

 Your TotalTime would just be a DateDiff statement on the start and end times.  

ex.  DateDiff(DateTimeValue(yourStartTimeInput.Text), DateTimeValue(yourEndTimeInput.Text), Minutes)

 

But you had originally stated that the Status chosen somehow impacted your recording of the values, so I'm not sure how that is fitting in to the logic.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

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 (3,616)