Diese Seite mit anderen teilen ...

Informationen zum Thema:
WinDev Forum
Beiträge im Thema:
Erster Beitrag:
vor 5 Jahren, 2 Monaten
Letzter Beitrag:
vor 5 Jahren, 1 Monat
Beteiligte Autoren:
John Marrone Jr, Alexandre Leclerc, Arie, DerekT, Fabrice Harari

Transform a time in seconds to ex: 1:12.34

Startbeitrag von John Marrone Jr am 23.03.2013 18:14


I need to take some time data I receive in seconds and transform the display output to look like 1:12.34. I receive the value as 72.34. I need to transform the value of 72 seconds and 34 hundredths of a second into a time format that looks like -> 1:12.34



you can do something like this
nMinutes is int = 72
nHours is int = IntegerPart(nMinutes/60)
nMinutes = nMinutes - (nHours*60)

now you have the hours (1) and the minutes (12)

Well you have to add some code yourself. To build the result and handle the seconds, but you get the idea.
Exit for me now, it's saturday evening over here.

von Arie - am 23.03.2013 19:32

Time and dates are never straightforward in WD - have to roll your own on this one.

Code I have used is

TimeRecd is real = 72.34
SecsRecd is int = IntegerPart(TimeRecd)
MinsOut is string = NoSpace(NumToString(SecsRecd / 60,"-2d"))
SecsOut is string = NumToString(modulo(SecsRecd,60),"-2d")
HunsOut is string = Right(DecimalPart(TimeRecd),2)

TimeOut is string = StringBuild("%1:%2:%3",MinsOut,SecsOut,HunsOut)

The NoSpace is used where the minute value is a < 10


von DerekT - am 23.03.2013 19:46

I hven't tested, but it seems to me that you should be able to do that quite easily with a TIME variable

MyTime is time=""

Then tyou can use TimeToString easily

Best regards

von Fabrice Harari - am 23.03.2013 20:47
Thanks for the help my friends. When I get back in town Wednesday I will give these methods a go. I am always greatful for the time and effort I receive here. I will let everyone know the results when I get back Wednesday and have given them a try.

Thanks again!!

von John Marrone Jr - am 25.03.2013 12:35
Hi John,

Just to sum up the best propositions in 3 lines of code:

duD is Duration
duD..InSeconds = “72.34”
Trace(DurationToString(duD,“MM:SS.LL”)) // Result: 01:12.34

Best regards,
Alexandre Leclerc

von Alexandre Leclerc - am 25.03.2013 19:52
And the winner is Alexandre :spos:

von Arie - am 25.03.2013 20:16

I tried all the different methods suggested but they all would leave the zero out such as 1:9.4 where I need 1:09.40. I need the zeros. I do thank everyone for your time and effort. If someone has the answer for me being able to get the zeros to show up let me know.

von John Marrone Jr - am 27.03.2013 20:06
Hi John,

Unless there is a problem I dont' know, the DurationToString() function inserts the zeros. Example:

duD is Duration; duD..InSeconds = “61.01”; Trace(DurationToString(duD,“MM:SS.LL”)) // Result: 01:01.01

All the zeros are present (in my test at least).

Best regards,
Alexandre Leclerc

von Alexandre Leclerc - am 28.03.2013 17:19
Hi Alex

Duration almost got me there. But I need 1:01.01

And doing DurationToString(duD,“M:SS.LL") would not take. Do you know how to leave the leading zero off by any chance??


von John Marrone Jr - am 28.03.2013 17:25
Hi John,

I see what you are looking for now. No there is no such function that I personally know of.

I don't know the requirements of your output but maybe this could do it:


Now if the minute part must give an hour after 59, you will have to make yourself a strip function to erase from left until you it a number. Like:

duD is Duration
duD..InSeconds = “61.01”
s is string = DurationToString(duD,“HH:MM:SS.LL”)
i is int = 1
WHILE s[[i]] IN ("0",":")

Best regards,
Alexandre Leclerc

Edit 1: Corrected loop to not use a variable (which was useless).
Edit 2: Corrected loop to use a variable (which is useless, but the smiles appears if not in the forum).

von Alexandre Leclerc - am 28.03.2013 17:52
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.