Data Access Worldwide Knowledge Base

Article ID 2089
Article Title HOWTO: Calculate the number of seconds from midnight
Article URL http://www.dataaccess.com/kbasepublic/kbprint.asp?ArticleID=2089
KBase Category VDF10
Date Created 02/21/2005
Last Edit Date 03/01/2005


Article Text
QUESTION:
I need a function that returns the number of seconds that passed since midnight. How do I do this since there is no built-in function for this?

ANSWER:
You can write a function and use something like:

Function SecondsFromMidNight Global Returns Integer
    DateTime dtNow dtZero
    TimeSpan tsDiff
    Integer iSeconds
    
    Move (CurrentDateTime ()) To dtNow
    Move (DateSetHour (dtNow, 0)) To dtZero
    Move (DateSetMinute (dtZero, 0)) To dtZero
    Move (DateSetSecond (dtZero, 0)) To dtZero
    
    Move (dtNow - dtZero) To tsDiff
    Move (SpanTotalSeconds (tsDiff)) To iSeconds
    
    Function_Return iSeconds
End_Function // SecondsFromMidNight

Send Info_Box (SecondsFromMidnight ())



Contributed By:
Vincent Oorsprong
Company: Data Access Worldwide
email: vincent.oorsprong@dataaccess.eu
Web Site: http://www.dataaccess.eu


Email this Article
Email this Article to a Colleague
Send Feedback on this Article to Data Access Worldwide
Copyright ©2010 Data Access Corporation. All rights reserved.

The information provided in the Data Access Technical Knowledge Base is provided "as is" without warranty of any kind. Data Access Corporation disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. In no event shall Data Access Corporation or its suppliers be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages, even if Data Access Corporation or its suppliers have been advised of the possibility of such damages. Some states do not allow the exclusion or limitation of liability for consequential or incidental damages so the foregoing limitation may not apply.