Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. 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 Databases 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 December 22nd, 2003, 12:20 PM
Authorized User
 
Join Date: Nov 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Time Validation Procedure

On one of my asp pages, I was passing a time value to a SQL Server stored procedure. The procedure, sp_help_jobhistory, would not accept a time value greater than the integer 235959. My time value was calculated, so there where situations where the integer would be something like 248434. I wrote this code to convert the value to one that would be accepted by the procedure:

<%
'Validate that intEndTime is not greater than 235959.
'Adjust intEndTime to an acceptable value if it is not.

    intUVEndTime = intStartTime + intRunTime

    Dim intTime, intHour, intMinute, intSecond
    Dim intNewMinute, intAdditionalHour, intAdditionalMinute
    Dim intFinalHour, intFinalMinute, intFinalSecond

    intTime = intUVEndTime

'The "Fix()" function returns the integer part of a number

    intHour = Fix((intTime / 10000))
    intMinute = Fix((intTime Mod 10000) / 100)
    intSecond = Fix((intTime Mod 100))

'The "Mod" operator returns the modulus of two numbers

    intNewMinute = (intMinute Mod 60)

    intAdditionalHour = Fix(intMinute / 60)
    intAdditionalMinute = Fix(intSecond / 60)

    intFinalHour = intHour + intAdditionalHour
    intFinalMinute = intNewMinute + intAdditionalMinute
    intFinalSecond = (intSecond Mod 60)

'The maximum time value accepted by the "sp_help_jobhistory" stored procedure is 235959. If intFinalHour is greater than 23, intEndTime will be set to 235959.

    If intFinalHour > 23 then
        intFinalHour = 23
        intFinalMinute = 59
        intFinalSecond = 59
    End If

'The "sp_help_jobhistory" stored procedure requires a leading zero for minute or second values between 0 and 9. The following code adds the leading zero and converts the new values to strings.

    strHour = CStr(intFinalHour)
    If intFinalMinute >= 0 and intFinalMinute <= 9 then
        strMinute = "0" & CStr(intFinalMinute)
    Else
        strMinute = CStr(intFinalMinute)
    End If

    If intFinalSecond >= 0 and intFinalSecond <= 9 then
        strSecond = "0" & CStr(intFinalSecond)
    Else
        strSecond = CStr(intFinalSecond)
    End If

    'Concatenate the strings
    strTime = strHour & strMinute & strSecond

    'Convert the concatenated string to a Long
    intNewTime = CLng(strTime)

    'Assign the new value to intEndTime
    intEndTime = intNewTime

    'Print the new time
    Response.Write "<br><br>intNewTime = " & intNewTime
%>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Standalone validation + web form validation morbo Struts 0 August 19th, 2008 04:02 AM
date time validation artarasan JSP Basics 2 December 4th, 2007 05:38 AM
Validation at Run Time nicesukhi Visual Studio 2005 0 July 20th, 2006 02:43 AM
comparing date/time fields on form validation Lucy Javascript How-To 1 June 20th, 2006 09:22 AM
stored procedure: time format/mismatch problem. MDM ASP.NET 2.0 Professional 1 April 12th, 2006 03:42 PM





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