Date Function

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:

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
Who is Participating?
dancebertConnect With a Mentor Commented:
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
Use the DateDiff Function

jennifereAuthor Commented:
That will work-  Thanks.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.