Consulting

Results 1 to 5 of 5

Thread: Solved: Date of 365 days ago.

  1. #1
    VBAX Regular
    Joined
    Mar 2005
    Posts
    67
    Location

    Solved: Date of 365 days ago.

    Hey guys.
    How can i find out the date (mm/dd/yyyy) of an x number of days from now backwards.
    Eg: what date would it be 300 days before 4/11/2005.


    Thank you
    Mike

  2. #2
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi Mike,

    Providing that your date is in the correct date format, it's actually a number. You should be able to just subtract 300 form it.

    Try throwing this in the immediate window and pressing enter. It should show you today's date - 300 days:

    [vba]debug.Print Now()-300[/vba]

    As long as your date is not a text string, you should be fine. If it is text, you'll need to convert it to a valid date first.

    HTH,
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  3. #3
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Mike

    Ken's method should work but you also might want to take a look at the DateAdd function or the DateDiff function.

  4. #4
    VBAX Regular
    Joined
    Mar 2005
    Posts
    67
    Location
    Thank you Ken,
    Works perfectly.

  5. #5
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Glad to be of help!

    FYI, though, if you ever need to add x months or years to a date though, be sure to check out Norie's suggestions, as they can be smart enough to deal with leap years and such.

    Cheers!
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





Posting Permissions

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