Solved

Date Function

Posted on 2003-12-01
3
706 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
  • 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now