# how to convert time value to numeric value

**URL:** <https://www.dynamicsuser.net/t/how-to-convert-time-value-to-numeric-value/39598>\
**Category:** Developer Forum\
**Created:** [August 10, 2012, 9:43am UTC](https://www.dynamicsuser.net/t/how-to-convert-time-value-to-numeric-value/39598 "2012-08-10T09:43:07Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![pizah](https://avatars.discourse-cdn.com/v4/letter/p/ed8c4c/32.png) [@pizah](https://www.dynamicsuser.net/u/pizah)\
**Post date:** [August 10, 2012, 9:43am UTC](https://www.dynamicsuser.net/t/how-to-convert-time-value-to-numeric-value/39598/1 "2012-08-10T09:43:07Z")

</div>

For example: start=11:00:00am

end=12:00:00pm

result=01:00:00am

But actual result i want is 1 hour…

Any advise…[:)]

---

<div class="post-metadata">

**Author:** ![mohana\_cse06](https://avatars.discourse-cdn.com/v4/letter/m/e480ec/32.png) [@mohana\_cse06](https://www.dynamicsuser.net/u/mohana_cse06)\
**Post date:** [August 10, 2012, 9:48am UTC](https://www.dynamicsuser.net/t/how-to-convert-time-value-to-numeric-value/39598/2 "2012-08-10T09:48:44Z")

</div>

create **timetaken** as global variable with datatype **Duration**

then write timetaken := end-start;

---

<div class="post-metadata">

**Author:** ![pizah](https://avatars.discourse-cdn.com/v4/letter/p/ed8c4c/32.png) [@pizah](https://www.dynamicsuser.net/u/pizah)\
**Post date:** [August 13, 2012, 1:51am UTC](https://www.dynamicsuser.net/t/how-to-convert-time-value-to-numeric-value/39598/3 "2012-08-13T01:51:43Z")

</div>

calculation part is correct but i still must convert from timeOfDay to str right?

so how to covert that ,can you share the coding…

---

<div class="post-metadata">

**Author:** ![mohana\_cse06](https://avatars.discourse-cdn.com/v4/letter/m/e480ec/32.png) [@mohana\_cse06](https://www.dynamicsuser.net/u/mohana_cse06)\
**Post date:** [August 14, 2012, 5:58am UTC](https://www.dynamicsuser.net/t/how-to-convert-time-value-to-numeric-value/39598/4 "2012-08-14T05:58:19Z")

</div>

Can you explain clearly…

what do you need?

---

<div class="post-metadata">

**Author:** ![pizah](https://avatars.discourse-cdn.com/v4/letter/p/ed8c4c/32.png) [@pizah](https://www.dynamicsuser.net/u/pizah)\
**Post date:** [August 16, 2012, 1:35am UTC](https://www.dynamicsuser.net/t/how-to-convert-time-value-to-numeric-value/39598/5 "2012-08-16T01:35:15Z")

</div>

I do calculation method as per your sugget to me…

then the result come out is 01:00:00am, if the start date=11:00:00am and end date=12:00:00pm…

But the actual result i need is 1 hour (make it in string/real/numeric)…can you share the coding…

My idea is maybe i must to convert the result to string…but i not familiar with coding of converting…please advise…[:)]

---

<div class="post-metadata">

**Author:** ![mohana\_cse06](https://avatars.discourse-cdn.com/v4/letter/m/e480ec/32.png) [@mohana\_cse06](https://www.dynamicsuser.net/u/mohana_cse06)\
**Post date:** [August 16, 2012, 5:13am UTC](https://www.dynamicsuser.net/t/how-to-convert-time-value-to-numeric-value/39598/6 "2012-08-16T05:13:37Z")

</div>

can you show your code and datatypes of global variabls…

as I suggested above, I got 1 hour only as output…

---

<div class="post-metadata">

**Author:** ![pizah](https://avatars.discourse-cdn.com/v4/letter/p/ed8c4c/32.png) [@pizah](https://www.dynamicsuser.net/u/pizah)\
**Post date:** [August 16, 2012, 8:52am UTC](https://www.dynamicsuser.net/t/how-to-convert-time-value-to-numeric-value/39598/7 "2012-08-16T08:52:23Z")

</div>

This is my code, please correct if i’m wrong;

display timeOfDay TimeCount()  
{  
timeOfDay difftime;  
difftime = this.endtime() - this.starttime();  
return difftime;  
}

---

<div class="post-metadata">

**Author:** ![mohana\_cse06](https://avatars.discourse-cdn.com/v4/letter/m/e480ec/32.png) [@mohana\_cse06](https://www.dynamicsuser.net/u/mohana_cse06)\
**Post date:** [August 16, 2012, 8:59am UTC](https://www.dynamicsuser.net/t/how-to-convert-time-value-to-numeric-value/39598/8 "2012-08-16T08:59:35Z")

</div>

so I guess you are working on AX and wrongly posted in NAV forum.

---

<div class="post-metadata">

**Author:** ![sekharg1980](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@sekharg1980](https://www.dynamicsuser.net/u/sekharg1980)\
**Post date:** [August 16, 2012, 9:09am UTC](https://www.dynamicsuser.net/t/how-to-convert-time-value-to-numeric-value/39598/9 "2012-08-16T09:09:14Z")

</div>

Hi Pizah,

I was developed one class for this type functionality

see document do want this class code reply me

**G Chandrasekhar Ax Technical Consultant**

**DayHourTime**

**DayHourTime** class developed for calculate the total days hours minutes seconds between start to end datetime

**inputs** StartDateTime and EndDateTime both are utcDateTime or StartTime and EndTime in the Seconds

**outputs** 2 days 23:30:20 or 71:30:20 called as method

**Objects and Methods**

str hours hours string in the formation hh

str minutes minutes string in the formation mm

str seconds seconds string in the formation ss

str hhMmSs formation hours,minutes and seconds hh,mm,ss

str hoursTime hourstime string inthe formation HH:MM:SS

str daysHoursTime daysHoursTime string inthe formation dd days HH:MM:SS

int quotient quotient int value for Dividend/Divisor

int totalTime totalTime int value for total seconds

int startTime startTime int value for start seconds

int endTime endTime int value for end seconds

int days days int value for total days

**Methods**

public int days(StartDateTime \_startDateTime,

EndDateTime \_endDateTime) returns a days int value defference between startdate and enddate

private int totalTime(StartDateTime \_startDateTime,

EndDateTime \_endDateTime) returns a totalseconds int defference between starttime and endtime

public int startTime(StartDateTime \_startDateTime) returns starttime int value in the seconds

public int endTime(EndDateTime \_endDateTime) returns endtime int value in the secounds

public str hours(int \_time) returns hours string in the total seconds

public str minutes(int \_time) returns minutes string in the total seconds

public str seconds(int \_time) returns seconds string in the total seconds

private str hhMmSs(int \_hhmmss) returns hhmmss string in the formation hh,mm,ss

public str hoursTime(int \_days, Str \_hours, Str \_minutes, Str \_seconds )

returns hoursTime string in the formation HH:MM:SS

public str daysHoursTime(int \_days, Str \_hours, Str \_minutes, Str \_seconds )

returns daysHoursTime string in the formation dd days HH:MM:SS

public str hoursTimeConsumed (StartDateTime \_startDateTime,

EndDateTime \_endDateTime) returns hoursTime string in theformation HH:MM:SS

public str daysHoursTimeConsumed (StartDateTime \_startDateTime,

EndDateTime \_endDateTime) returns daysHoursTime string in the formation dd days HH:MM:SS

public str timeConsumedHoursTime(int \_startTime, int \_endTime)

returns hoursTime string in theformation HH:MM:SS

public str timeConsumedDaysHoursTime(int \_startTime, int \_endTime)

returns daysHoursTime string in the formation dd days HH:MM:SS

---

<div class="post-metadata">

**Author:** ![MartinDrab](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@MartinDrab](https://www.dynamicsuser.net/u/MartinDrab)\
**Post date:** [August 16, 2012, 12:33pm UTC](https://www.dynamicsuser.net/t/how-to-convert-time-value-to-numeric-value/39598/10 "2012-08-16T12:33:59Z")

</div>

If you want a result like “1 hour”, it’s actually not a time of day, it’s a duration (or a TimeSpan in .NET terminology). When you realize that AX time is number of seconds since midnight, you can easily write something like strFmt("%1 hours", time div 3600).

---

<div class="post-metadata">

**Author:** ![sekharg1980](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@sekharg1980](https://www.dynamicsuser.net/u/sekharg1980)\
**Post date:** [August 16, 2012, 1:14pm UTC](https://www.dynamicsuser.net/t/how-to-convert-time-value-to-numeric-value/39598/11 "2012-08-16T13:14:37Z")

</div>

but asks time formats like HH:MM:SS

how to convert like that

---

<div class="post-metadata">

**Author:** ![MartinDrab](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@MartinDrab](https://www.dynamicsuser.net/u/MartinDrab)\
**Post date:** [August 16, 2012, 2:02pm UTC](https://www.dynamicsuser.net/t/how-to-convert-time-value-to-numeric-value/39598/12 "2012-08-16T14:02:22Z")

</div>

@Sekharg: Look at X++ methods like time2str() or sime2StrHMS() or time2StrHMLeadingZero().

---

<div class="post-metadata">

**Author:** ![sekharg1980](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@sekharg1980](https://www.dynamicsuser.net/u/sekharg1980)\
**Post date:** [August 16, 2012, 2:38pm UTC](https://www.dynamicsuser.net/t/how-to-convert-time-value-to-numeric-value/39598/13 "2012-08-16T14:38:36Z")

</div>

hi Martin,

it is correct

it’s good

thanks all

thanks

sekharg

---

<div class="post-metadata">

**Author:** ![DurgaDevi](https://avatars.discourse-cdn.com/v4/letter/d/ba8739/32.png) [@DurgaDevi](https://www.dynamicsuser.net/u/DurgaDevi)\
**Post date:** [August 16, 2012, 2:48pm UTC](https://www.dynamicsuser.net/t/how-to-convert-time-value-to-numeric-value/39598/14 "2012-08-16T14:48:10Z")

</div>

Hi Martin its great reply.

Thanks

Rav
