ONE week back

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

ONE week back

Post by sal21 »

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

User avatar
HansV
Administrator
Posts: 78483
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: ONE week back

Post by HansV »

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.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

Re: ONE week back

Post by sal21 »

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.
dtmDate = DateSerial(2010,6,7)
wich part of my string i can insert???

User avatar
HansV
Administrator
Posts: 78483
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: ONE week back

Post by HansV »

Where does the string come from? If possible, you should avoid using it.
Best wishes,
Hans

User avatar
Goshute
3StarLounger
Posts: 397
Joined: 24 Jan 2010, 19:43
Location: Salt Lake City, Utah, USA

Re: ONE week back

Post by Goshute »

sal21 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
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 are
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

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

Re: ONE week back

Post by sal21 »

Goshute wrote:
sal21 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
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 are
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")
Godd solution......... tks.