Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript to alter text based on date

Status
Not open for further replies.

kleinicus

MIS
Dec 4, 2002
98
US
Hello all.
Here's what I've got. I have a bunch of .URL files in my Favorites folder. I have to go to these links once a day so that I can copy the charts that they generate. The problem is that the links are static, whereas I need to change the URL slightly every day. The URL contains a date stamp (along with a lot of other variables) that looks like this:
Code:
...output=Histogram&from=2008%2D04%2D04+00%3A00%3A00&to=2008%2D04%2D04+23%3A59%3A59...

You can see that there are two dates here (2008-04-04). The values that I need to change are the last two digits of the date (the day) because it's in year, month, day format.
I am after two separate things. First, I would like to find a way to do this text alteration automatically using VBScript. Ideally, it would read the current system date as an integer value, subtract one (since I'm after the previous day), and update those portions of the date stamp accordingly. Second, since the script would probably have to treat them as text files, I would need the script to be able to change the file extension in a "save as" type of operation.

 
See if this gets you started

Code:
Option Explicit

Dim strTemp : strTemp = "output=Histogram&from=2008%2D04%2D04+00%3A00%3A00&to=2008%2D04%2D04+23%3A59%3A59..."
Dim RegEx : Set RegEx = New RegExp
RegEx.Pattern = "2008%2D\d{2}%2D\d{2}"
RegEx.IgnoreCase = True
RegEx.Global = True

WScript.Echo RegEx.Replace(strTemp, GetPrevDate)

Function GetPrevDate
	Dim dt1 : dt1 = Date() - 1
	GetPrevDate = Year(dt1) & "%2D" & _
				  Right("00" & Month(dt1), 2) & "%2D" & _
				  Right("00" & Day(dt1), 2) & "%2D"
End Function

As far as udating the links you can look at WSHShell:
You should really try and put something together on your own and let us know if you have any issues.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top