Results 1 to 5 of 5

Thread: Returning a Decimal Place from DateDiff Function

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    3

    Returning a Decimal Place from DateDiff Function

    Hi All,

    I was wondering how I could return number of weeks between two dates but getting the result including at least 4 decimal places. I know that the datediff function returns an integer so I'm guessing this function won't do the job. I'm working in Excel by the way.

    I know I could just return the number of days and then divide by seven and put that into a double variable but I need the decimal places to change every time I refresh them and doing it this way they would only change once a day when the day value changes. So I guess the question is also can I return the day value in decimal places

    Does anyone have any suggestions on how to tackle this?

    Thanks

    Lloyd

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Returning a Decimal Place from DateDiff Function

    Hi lloydmav, welcome to VBForums!

    You are right that DateDiff will only return integer values, and your thinking of using a smaller period then dividing is the way to get the value to 4 dp's.

    I would recommend going for a period smaller than days, possibly hours (or minutes) instead. You would then divide by appropriate values, eg:

    your_value = (datediff_value) / 24 / 7

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Returning a Decimal Place from DateDiff Function

    To get the number of weeks in DateDiff, use "ww" as the first parameter.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    3

    Re: Returning a Decimal Place from DateDiff Function

    Quote Originally Posted by si_the_geek
    Hi lloydmav, welcome to VBForums!

    You are right that DateDiff will only return integer values, and your thinking of using a smaller period then dividing is the way to get the value to 4 dp's.

    I would recommend going for a period smaller than days, possibly hours (or minutes) instead. You would then divide by appropriate values, eg:

    your_value = (datediff_value) / 24 / 7
    Ah of course, start from a smaller number, thats great, thanks for the help

  5. #5
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Returning a Decimal Place from DateDiff Function

    Dates are numbers.. 1 = 1 day.
    So you could just minus one from the other and divide by 7... (you may need cdbl function if in code to force into a double).

    Just another way

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

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