I have this a var filled with 20100607-20100611 is a week
How to calculate (and return in the same format) a week back based thi var?
in this case the new var = 20100531-20100604
ONE week back
-
- Administrator
- Posts: 78686
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: ONE week back
I'd use a date variable instead, and calculate the string from it:
Dim dtmDate As Date
Dim strWeek As String
dtmDate = DateSerial(2010,6,7)
strWeek = Format(dtmDate, "yyyymmdd") & "-" & Format(dtmDate + 4, "yyyymmdd")
To go back a week, simply subtract 7 from dtmDate.
Dim dtmDate As Date
Dim strWeek As String
dtmDate = DateSerial(2010,6,7)
strWeek = Format(dtmDate, "yyyymmdd") & "-" & Format(dtmDate + 4, "yyyymmdd")
To go back a week, simply subtract 7 from dtmDate.
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4384
- Joined: 26 Apr 2010, 17:36
Re: ONE week back
dtmDate = DateSerial(2010,6,7)HansV wrote:I'd use a date variable instead, and calculate the string from it:
Dim dtmDate As Date
Dim strWeek As String
dtmDate = DateSerial(2010,6,7)
strWeek = Format(dtmDate, "yyyymmdd") & "-" & Format(dtmDate + 4, "yyyymmdd")
To go back a week, simply subtract 7 from dtmDate.
wich part of my string i can insert???
-
- Administrator
- Posts: 78686
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: ONE week back
Where does the string come from? If possible, you should avoid using it.
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 397
- Joined: 24 Jan 2010, 19:43
- Location: Salt Lake City, Utah, USA
Re: ONE week back
I agree strongly with Hans that it's much easier to Dimension dates as Date Type and work with them that way. However, where your strings aresal21 wrote:I have this a var filled with 20100607-20100611 is a week
How to calculate (and return in the same format) a week back based thi var?
in this case the new var = 20100531-20100604
Dim myWeekString as String, strNewVar as String
see if this works:
strNewVar = format(dateserial(left(myWeekString, 4),mid(myWeekString, 5,2),mid(myWeekString, 7,2)-7),"yyyymmdd") & "-" & format(dateserial(mid(myWeekString, 10,4),mid(myWeekString, 14,2),mid(myWeekString, 16,2)-7),"yyyymmdd")
Goshute
I float in liquid gardens
I float in liquid gardens
-
- PlatinumLounger
- Posts: 4384
- Joined: 26 Apr 2010, 17:36
Re: ONE week back
Godd solution......... tks.Goshute wrote:I agree strongly with Hans that it's much easier to Dimension dates as Date Type and work with them that way. However, where your strings aresal21 wrote:I have this a var filled with 20100607-20100611 is a week
How to calculate (and return in the same format) a week back based thi var?
in this case the new var = 20100531-20100604
Dim myWeekString as String, strNewVar as String
see if this works:
strNewVar = format(dateserial(left(myWeekString, 4),mid(myWeekString, 5,2),mid(myWeekString, 7,2)-7),"yyyymmdd") & "-" & format(dateserial(mid(myWeekString, 10,4),mid(myWeekString, 14,2),mid(myWeekString, 16,2)-7),"yyyymmdd")