Wrox Programmer Forums
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 21st, 2003, 02:05 PM
Registered User
Join Date: Jul 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Time: formatting from seconds to serial

I need to take a time value expressed in seconds and convert it to a time value expressed in a serial fashion (xx:xx:xx). Is there an easy way to do this?



Old July 22nd, 2003, 03:49 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post

A simple recursive function like this will work for anything up to 219599 seconds (thats 60 hours, 59 minutes, 59 seconds), though you will have to add some formatting to get leading zeros:
Public Function SecsToSerial(x)

    If x > 60 Then
        SecsToSerial = SecsToSerial(x \ 60) & ":" & x Mod 60
        SecsToSerial = x
    End If

End Function
Old July 22nd, 2003, 04:00 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts

'Function takes a number of seconds and returns
'in format hours:Mins:Secs
function TimeAsHMS(secondsIn)

    'Calc hours
    hours = (secondsIn - secondsIn mod 3600)/3600
    secondsIn = secondsIn - (hours * 3600)
    'Calc Mins
    mins = (secondsIn - secondsIn mod 60)/60
    secondsIn = secondsIn - (mins * 60)
    'Secs left
    secs = secondsIn

    TimeAsHMS = hours & ":" & mins & ":" & secs

end function

They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting Time Output braunj ASP.NET 2.0 Basics 0 October 6th, 2008 10:27 PM
Convert time in seconds to hh:mm:ss 41509331 C++ Programming 0 March 18th, 2008 04:43 AM
Converting Seconds into Nano seconds and viceversa chandu80 General .NET 0 June 4th, 2005 01:18 AM
formatting date time Adam H-W Classic ASP Basics 4 September 29th, 2004 03:35 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.