[Solved] how do i get a number into a Duration field?

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
Jaymer
Posts: 1828
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

[Solved] how do i get a number into a Duration field?

Post by Jaymer »

If I have a numeric field that contains the integer # 41, how do I get that into a Duration field so that it displays "1 days 17 hours, etc." ?
It might also be 41.5 for 41 hrs, 30 mins
Last edited by Jaymer on Tue Sep 10, 2019 12:32 am, edited 2 times in total.
Click Here to see a collection of my tips & hacks on this forum? Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
Jaymer
Posts: 1828
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: how do i get a number into a Duration field?

Post by Jaymer »

... or another example:

if you were record times, its not quick to have a user enter 8:30 because
1) You cannot use 10-key pad - you have to enter the :
2) User wants to enter 8.5 for 8 1/2 hours (not enter 8 hrs 30 mins)

So for quick entry, you could allow time entry into a numeric field, THEN convert it into a Duration.
But I can't seem to just a simple : timeentry.DurationField = timeentry.NumericField

The duration always shows 0
Click Here to see a collection of my tips & hacks on this forum? Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
Jaymer
Posts: 1828
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: how do i get a number into a Duration field?

Post by Jaymer »

ok, here's a not so elegant solution:

Code: Select all

TicketTime.Timestamp_test = TIME_ADD( AS_TIMESTAMP('01-01-2000 00:00' , 'MM-dd-yy HH:mm'), TicketTime.resource_sch_time_hours )

TicketTime.Duration_test = TIME_ADD( AS_TIMESTAMP('01-01-2000 00:00' , 'MM-dd-yy HH:mm'), TicketTime.resource_sch_time_hours )

TicketTime.Duration_test = TicketTime.Timestamp_test - AS_TIMESTAMP('01-01-2000 00:00' , 'MM-dd-yy HH:mm')
I need a dummy timestamp field to store the result of adding Hrs&Mins to midnight.
Now, I subtract that from midnight to get a duration.


Written as 1 line now:

Code: Select all

TicketTime.Duration=TIME_ADD(AS_TIMESTAMP('01-01-2000 00:00','MM-dd-yy HH:mm'),TicketTime.resource_sch_time_hours)-AS_TIMESTAMP('01-01-2000 00:00','MM-dd-yy HH:mm')
Click Here to see a collection of my tips & hacks on this forum? Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
eagles9999
Posts: 2197
Joined: Mon Jul 02, 2012 12:24 am
Location: Ulaanbaatar, Mongolia

Re: how do i get a number into a Duration field?

Post by eagles9999 »

I just use HHh MMm for the format

Displays as...
Screen Shot 2019-09-10 at 7.38.05 am.png
Screen Shot 2019-09-10 at 7.38.05 am.png (8.5 KiB) Viewed 3680 times
Cheers,
Mark
_________________
AwareIM 6.0, 8.4, 8.5b (build 2806) MS SQL Server 2012 / MariaDB, Windows 10, Ubuntu Linux, Theme: Default, Browser: Chrome
Upcloud, AWS
Image
Jaymer
Posts: 1828
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: how do i get a number into a Duration field?

Post by Jaymer »

MARK -->
Jaymer wrote:If I have a numeric field that contains the integer # 41, how do I get that into a Duration field so that it displays "1 days 17 hours, etc." ?
It might also be 41.5 for 41 hrs, 30 mins
You can't just assign a number (41 for ex.) to a Duration field.
Click Here to see a collection of my tips & hacks on this forum? Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
eagles9999
Posts: 2197
Joined: Mon Jul 02, 2012 12:24 am
Location: Ulaanbaatar, Mongolia

Re: how do i get a number into a Duration field?

Post by eagles9999 »

Ah... misread...

Just assign the value 147,600,000 to the Duration attribute and set its diaplay format to DDd HHh MMm
Cheers,
Mark
_________________
AwareIM 6.0, 8.4, 8.5b (build 2806) MS SQL Server 2012 / MariaDB, Windows 10, Ubuntu Linux, Theme: Default, Browser: Chrome
Upcloud, AWS
Image
Jaymer
Posts: 1828
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: how do i get a number into a Duration field?

Post by Jaymer »

Actually, you CAN assign a number to a Duration field if you know the formula.
Duration is a BIGINT field that store MILLISECONDS.
So if you want to set a Duration of 1 hour, you just set that field to 3,600,000
... and off you go.

If you want to store a duration and you have your values in 2 diff fields (myHrs, myMin) then its:
BO.Duration = BO.myHrs * 3600000 + BO.myMin * 60000
The Duration for 4.25hrs is 15300000

--> JaymerTip
Click Here to see a collection of my tips & hacks on this forum? Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
Post Reply