CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Guest

    Calling VB brains, do it yourself date and time function

    Hello, I have a problem for the VB brains out there. I need to write a function that will accept 2 dates and times, and it needs to return the difference in days, and the amount of time passed in 100ths of seconds. If the dates and times are the same, the function should return zero. The variable dates and times will be passed in no specific order, so it will have to be determined which is the earlier date and time. I know about the existing date functions supplied by VB, I need to write the code without these functions. Anyone have a solution?? Or some good starting points??


  2. #2
    Guest

    Re: Calling VB brains, do it yourself date and time function

    HELLO I AM HERE BECAUSE HE SAID CALLING ALL VB BRAINS AND WHEN I READ THAT I JUST LOOKED AROUND AND ONLY SAY MYSELF SITTING THERE SO THEREFORE I AM THE ONE AND BEST AND ONLY VB BRAIN THAT CAN HELP YOU. WELL ANYWAY ON TO YOUR PROBLEM (YOU GUYS HAVE SO MANY....HEHE CUTE LIL BEGINNERS). THE FUNCTION YOU NEED FOR 2 DATES IS IN THIS CODE I AM WRITING HERE.
    FUNCTION WRITE()
    INT MAIN()
    FORM2.SHOW FUNCTION WRITE=TRUE
    IF FORM2.SHOW FUNCTION WRITE=FALSE THEN
    ORDER KILL.TRUE ON FUNCTION
    ELSE
    'THIS I WHERE IT GETS TRICKY
    UNDO KILL.TRUE
    THERE MY FRIEND I THINK THAT SHOULD WET YOUR WHISTLE ENOUGH FOR TODAY....WELL TELL ME HOW IT GOES! GOOD LUCK!


  3. #3
    Join Date
    Aug 1999
    Location
    US, Florida
    Posts
    817

    Re: Calling VB brains, do it yourself date and time function

    *** was that? that was BS not a VB code, looks like some parts form C++ but it's basically all garbage, so Mr.VbBrain, <beep> wrong answer!!!


  4. #4
    Guest

    Re: Calling VB brains, do it yourself date and time function

    HEY MAN THIS IS A FRIENDLY WEBSITE SO JUST BECAUSE YOU CANNOT WRITE MASTER CODE SUCH AS I DO THAT DOESN'T MEAN YOU HAVE TO CRY OK?


  5. #5
    Join Date
    Aug 1999
    Location
    US, Florida
    Posts
    817

    Re: Calling VB brains, do it yourself date and time function

    You got problems with atitude, you got to go see a doctor or something......


  6. #6
    Guest

    Re: Calling VB brains, do it yourself date and time function

    LOL well that was amusing, but I really was hoping for some good ideas. Do you have any thing to share Andy?


  7. #7
    Guest

    Re: Calling VB brains, do it yourself date and time function

    Hi Andy, if you have any good ideas about this, I'd love to hear them. The other code submitted was obviously a joke.


  8. #8
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Calling VB brains, do it yourself date and time function

    This is quite straightforward using the Abs function and the DateDiff function that VB provides, eg:


    '
    ' Assumes that dteDate1 and dteDate2 already have a value and are
    ' of the VB type 'date'
    '
    MsgBox "Days Difference between Dates = " & Abs(DateDiff("d", dteDate1, dteDate2))
    MsgBox "Hours Difference between Dates = " & Abs(DateDiff("h", dteDate1, dteDate2))
    MsgBox "Minutes between dates = " & Abs(DateDiff("n", dteDate1, dteDate2))
    MsgBox "Seconds between dates = " & Abs(DateDiff("s", dteDate1, dteDate2))
    '




    - using the method above, it doesn't matter which date is the most recent or in which order.


    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

  9. #9
    Guest

    Re: Calling VB brains, do it yourself date and time function

    Thank you Chris, I was hoping to be able to write the function without the use of predefined VB functions, but your input is appreciated.


  10. #10
    Join Date
    Feb 2000
    Location
    Indiana
    Posts
    308

    Re: Calling VB brains, do it yourself date and time function

    You really don't want to not use the intrinsic VB date functions. I've had to maintain code where the programmer didn't know of the built in date/time functions and it was a nightmare. There were three integer variables (dd, mm, and yy) and he went through all sorts of hoops to get where he wanted to go. DateDiff took him nearly 40 lines of code and the logic was flawed (did not allow for leap years). Bottom line is, you cannot write most functions that VB offers more efficiently than they already are. That said, how about something like this:

    public Function Foo(dtDate1 as date, _
    dtDate2 as date, _
    byref iNumDays as Integer, _
    byref iNumSeconds as Integer) as Integer
    '******************************
    ' date Data Type Only Stores
    ' to the second, so we'll only
    ' compute to the second instead
    ' of the 1/100th
    '*******************************
    iNumDays = Abs(DateDiff("d", dtDate1, dtDate2))
    iNumSeconds = Abs(DateDiff("s", dtDate1, dtDate2))
    'The return value will be zero if the
    'dates are on the same day
    Foo = iNumDays
    End Function





  11. #11
    Join Date
    Feb 2000
    Posts
    149

    Re: Calling VB brains, do it yourself date and time function

    Thanks Kyle Ill try to give it a shot, much appreciated!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured