Hi guys,
I'v got this problem: How to convert seconds into hh:mm:ss format?
for example: I have 3601 seconds in integer, I want to convert it into 01:00:01
string format.
can anyone show me a function to get this done?
thanks.
Printable View
Hi guys,
I'v got this problem: How to convert seconds into hh:mm:ss format?
for example: I have 3601 seconds in integer, I want to convert it into 01:00:01
string format.
can anyone show me a function to get this done?
thanks.
Try:
DateAdd("s", 3601, #12:00am#)
Steve.
"convert" <zhang5gor@yahoo.com> wrote in message
news:3d00bf0a$1@10.1.10.29...
>
> Hi guys,
>
> I'v got this problem: How to convert seconds into hh:mm:ss format?
>
> for example: I have 3601 seconds in integer, I want to convert it into
01:00:01
> string format.
>
> can anyone show me a function to get this done?
>
> thanks.
>
If you actually want a string then use the Format function on the result.
Format(DateAdd("s", 3601, #12:00am#), "hh:mm:ss am/pm")
for example.
Steve.
"GunPaq" <steve@kcfsi.com> wrote in message news:3d00d258@10.1.10.29...
> Try:
>
> DateAdd("s", 3601, #12:00am#)
>
> Steve.
>
> "convert" <zhang5gor@yahoo.com> wrote in message
> news:3d00bf0a$1@10.1.10.29...
> >
> > Hi guys,
> >
> > I'v got this problem: How to convert seconds into hh:mm:ss format?
> >
> > for example: I have 3601 seconds in integer, I want to convert it into
> 01:00:01
> > string format.
> >
> > can anyone show me a function to get this done?
> >
> > thanks.
> >
>
>
Whoops, forgot I was in asp. Try FormatDateTime instead.
"GunPaq" <steve@kcfsi.com> wrote in message news:3d00d331$1@10.1.10.29...
> If you actually want a string then use the Format function on the result.
>
> Format(DateAdd("s", 3601, #12:00am#), "hh:mm:ss am/pm")
>
> for example.
>
> Steve.
>
> "GunPaq" <steve@kcfsi.com> wrote in message news:3d00d258@10.1.10.29...
> > Try:
> >
> > DateAdd("s", 3601, #12:00am#)
> >
> > Steve.
> >
> > "convert" <zhang5gor@yahoo.com> wrote in message
> > news:3d00bf0a$1@10.1.10.29...
> > >
> > > Hi guys,
> > >
> > > I'v got this problem: How to convert seconds into hh:mm:ss format?
> > >
> > > for example: I have 3601 seconds in integer, I want to convert it into
> > 01:00:01
> > > string format.
> > >
> > > can anyone show me a function to get this done?
> > >
> > > thanks.
> > >
> >
> >
>
>
Try this:
'get raw values
nSec = 3601
nMin = cint(nSec/60)
nHr = cint(nMin/60)
'take just the remainder to eliminate the part handled by larger
increments
nSec = nSec mod 60
nMin = nMin mod 60
'format for display with leading zeroes
if len(nSec) = 0 then nSec = "00" elseif len(nSec) = 1 then nSec = "0" &
nSec
' repeat this line for nMin and nHr
sTime = nDay & ":" & nHr & ":" & nMin & ":" & nSec
> >> "convert" <zhang5gor@yahoo.com> wrote in message
> >> news:3d00bf0a$1@10.1.10.29...
> >> > I've got this problem: How to convert seconds into hh:mm:ss
format?
> >> > for example: I have 3601 seconds in integer, I want to convert it
into
> >> 01:00:01
> >> > string format.
Hello Steve,
Thanks for your response.
I think I did not make the question clear.
1. I do not need am/pm;
2. 3601 is the result of rs("TotalSeconds");
3. The result 01:00:01 is string for hh:mm:ss; and,
4. I use VBScript on my asp.
Any new thoughts?
Thanks.
"GunPaq" <steve@kcfsi.com> wrote:
>If you actually want a string then use the Format function on the result.
>
>Format(DateAdd("s", 3601, #12:00am#), "hh:mm:ss am/pm")
>
>for example.
>
>Steve.
>
>"GunPaq" <steve@kcfsi.com> wrote in message news:3d00d258@10.1.10.29...
>> Try:
>>
>> DateAdd("s", 3601, #12:00am#)
>>
>> Steve.
>>
>> "convert" <zhang5gor@yahoo.com> wrote in message
>> news:3d00bf0a$1@10.1.10.29...
>> >
>> > Hi guys,
>> >
>> > I'v got this problem: How to convert seconds into hh:mm:ss format?
>> >
>> > for example: I have 3601 seconds in integer, I want to convert it into
>> 01:00:01
>> > string format.
>> >
>> > can anyone show me a function to get this done?
>> >
>> > thanks.
>> >
>>
>>
>
>
What Kris said on the calculation. :)
An alternate method to pad the leading zeros would be to use the String
function or a do-while loop:
nSec = String(2 - Len(nSec), "0") & nSec
or
do while Len(nSec) < 2
nSec = "0" & nSec
loop
This may not be such a big deal for two digits, but would be for more. For
example if you wanted to display 27 as 000027 then:
MyVal = 27
MyStr = String(6 - Len(MyVal), "0") & MyVal
instead of:
if ... elseif ... elseif ... elseif ......
You could then create your own general function - something like:
Function PadLeadingZeros(ValueToPad, TotalLength)
ValueToPad = Trim(ValueToPad)
PadLeadingZeros = ValueToPad
If Len(ValueToPad) > TotalLength Then Exit Function
PadLeadingZeros = String(TotalLength - Len(ValueToPad), "0") &
ValueToPad
End Function
Steve.
"Kris Eiben" <eibenkthisisforspammers@yahoo.com> wrote in message
news:3d00dcf6@10.1.10.29...
> Try this:
>
> 'get raw values
> nSec = 3601
> nMin = cint(nSec/60)
> nHr = cint(nMin/60)
>
> 'take just the remainder to eliminate the part handled by larger
> increments
> nSec = nSec mod 60
> nMin = nMin mod 60
>
> 'format for display with leading zeroes
> if len(nSec) = 0 then nSec = "00" elseif len(nSec) = 1 then nSec = "0" &
> nSec
> ' repeat this line for nMin and nHr
>
> sTime = nDay & ":" & nHr & ":" & nMin & ":" & nSec
>
> > >> "convert" <zhang5gor@yahoo.com> wrote in message
> > >> news:3d00bf0a$1@10.1.10.29...
> > >> > I've got this problem: How to convert seconds into hh:mm:ss
> format?
> > >> > for example: I have 3601 seconds in integer, I want to convert it
> into
> > >> 01:00:01
> > >> > string format.
>
>
>
Hi guys,
thank you for your responses.
However, when I tested 3690, by using Kris's suggestion, it gives me 01:02:30
due to the rounding of 9/60=1.5 it gets 2 because the ABS(1.5), which it
shoule turn to 1, but it gets 2.
Any new thoughts?
thank you!
"GunPaq" <steve@kcfsi.com> wrote:
>What Kris said on the calculation. :)
>
>An alternate method to pad the leading zeros would be to use the String
>function or a do-while loop:
>
>nSec = String(2 - Len(nSec), "0") & nSec
>
>or
>
>do while Len(nSec) < 2
> nSec = "0" & nSec
>loop
>
>This may not be such a big deal for two digits, but would be for more.
For
>example if you wanted to display 27 as 000027 then:
>
>MyVal = 27
>MyStr = String(6 - Len(MyVal), "0") & MyVal
>
>instead of:
>
>if ... elseif ... elseif ... elseif ......
>
>You could then create your own general function - something like:
>
>Function PadLeadingZeros(ValueToPad, TotalLength)
> ValueToPad = Trim(ValueToPad)
>
> PadLeadingZeros = ValueToPad
>
> If Len(ValueToPad) > TotalLength Then Exit Function
>
> PadLeadingZeros = String(TotalLength - Len(ValueToPad), "0") &
>ValueToPad
>End Function
>
>Steve.
>
>"Kris Eiben" <eibenkthisisforspammers@yahoo.com> wrote in message
>news:3d00dcf6@10.1.10.29...
>> Try this:
>>
>> 'get raw values
>> nSec = 3601
>> nMin = cint(nSec/60)
>> nHr = cint(nMin/60)
>>
>> 'take just the remainder to eliminate the part handled by larger
>> increments
>> nSec = nSec mod 60
>> nMin = nMin mod 60
>>
>> 'format for display with leading zeroes
>> if len(nSec) = 0 then nSec = "00" elseif len(nSec) = 1 then nSec = "0"
&
>> nSec
>> ' repeat this line for nMin and nHr
>>
>> sTime = nDay & ":" & nHr & ":" & nMin & ":" & nSec
>>
>> > >> "convert" <zhang5gor@yahoo.com> wrote in message
>> > >> news:3d00bf0a$1@10.1.10.29...
>> > >> > I've got this problem: How to convert seconds into hh:mm:ss
>> format?
>> > >> > for example: I have 3601 seconds in integer, I want to convert
it
>> into
>> > >> 01:00:01
>> > >> > string format.
>>
>>
>>
>
>
Try "int" instead of "cint."
Both Int and Fix remove the fractional part of number and return the
resulting integer value.
"convert" <zhang5gor@yahoo.com> wrote in message
news:3d0373b9$1@10.1.10.29...
>
> Hi guys,
>
> thank you for your responses.
>
> However, when I tested 3690, by using Kris's suggestion, it gives me
01:02:30
> due to the rounding of 9/60=1.5 it gets 2 because the ABS(1.5), which
it
> shoule turn to 1, but it gets 2.
>
> Any new thoughts?
>
> thank you!
>
>
> "GunPaq" <steve@kcfsi.com> wrote:
> >What Kris said on the calculation. :)
> >
> >An alternate method to pad the leading zeros would be to use the
String
> >function or a do-while loop:
> >
> >nSec = String(2 - Len(nSec), "0") & nSec
> >
> >or
> >
> >do while Len(nSec) < 2
> > nSec = "0" & nSec
> >loop
> >
> >This may not be such a big deal for two digits, but would be for
more.
> For
> >example if you wanted to display 27 as 000027 then:
> >
> >MyVal = 27
> >MyStr = String(6 - Len(MyVal), "0") & MyVal
> >
> >instead of:
> >
> >if ... elseif ... elseif ... elseif ......
> >
> >You could then create your own general function - something like:
> >
> >Function PadLeadingZeros(ValueToPad, TotalLength)
> > ValueToPad = Trim(ValueToPad)
> >
> > PadLeadingZeros = ValueToPad
> >
> > If Len(ValueToPad) > TotalLength Then Exit Function
> >
> > PadLeadingZeros = String(TotalLength - Len(ValueToPad), "0") &
> >ValueToPad
> >End Function
> >
> >Steve.
> >
> >"Kris Eiben" <eibenkthisisforspammers@yahoo.com> wrote in message
> >news:3d00dcf6@10.1.10.29...
> >> Try this:
> >>
> >> 'get raw values
> >> nSec = 3601
> >> nMin = cint(nSec/60)
> >> nHr = cint(nMin/60)
> >>
> >> 'take just the remainder to eliminate the part handled by larger
> >> increments
> >> nSec = nSec mod 60
> >> nMin = nMin mod 60
> >>
> >> 'format for display with leading zeroes
> >> if len(nSec) = 0 then nSec = "00" elseif len(nSec) = 1 then nSec =
"0"
> &
> >> nSec
> >> ' repeat this line for nMin and nHr
> >>
> >> sTime = nDay & ":" & nHr & ":" & nMin & ":" & nSec
> >>
> >> > >> "convert" <zhang5gor@yahoo.com> wrote in message
> >> > >> news:3d00bf0a$1@10.1.10.29...
> >> > >> > I've got this problem: How to convert seconds into hh:mm:ss
> >> format?
> >> > >> > for example: I have 3601 seconds in integer, I want to
convert
> it
> >> into
> >> > >> 01:00:01
> >> > >> > string format.
> >>
> >>
> >>
> >
> >
>