Solved

Date Function

Posted on 2003-12-01
3
713 Views
Last Modified: 2010-05-03
I am trying to use the Date function to return a date range from the current date to 5 days back.  The trick is it needs to be formatted like this:
2003-11-15-2003-11-30

Below is my orginal code.  However, as I discovered this morning, it doesn't take into consideration month changes or leap years.  Is there an easy way to do this??
   
daysBack = Year(Date) & "-" & Month(Date) & "-" & Day(Date) - 5
currentDate = Year(Date) & "-" & Month(Date) & "-" & Day(Date)  
rangeDate = daysBack & "-" & currentDate
0
Comment
Question by:jennifere
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 9

Expert Comment

by:dancebert
ID: 9852178
Use the DateDiff Function

0
 
LVL 9

Accepted Solution

by:
dancebert earned 125 total points
ID: 9852202
Oops, I meant the DateAdd fuction

Dim currentDate As Date
currentDate = Now
Dim daysBack As Date
daysBack = DateAdd("d", -5, currentDate)
rangeDate = cstr(daysBack) & "-" & currentDate
0
 

Author Comment

by:jennifere
ID: 9852265
That will work-  Thanks.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question