We help IT Professionals succeed at work.
Get Started

Get the difference between 2 dates in RegEx (ASP Classic)

226 Views
Last Modified: 2016-01-31
Hello All;

I need to get the different between 2 dates inside of a RegEx script.
The following script demonstrates one that works, and the other that does not work.

<%
Function Reggex(strString, strPattern, strReplace)

	Dim RE: Set RE = New RegExp

	With RE
		.Pattern = strPattern
		.Global = True
		.IgnoreCase = True
		Reggex = .Replace(strString, strReplace)
	End With
	
End Function

Function ReplaceChar(strString)
fromDate="1-Jan-2000"
toDate=date
strString = Reggex(strString, "\[BusDate\]", ""&DateDiff("yyyy",fromDate,toDate)&"") 

'This will give the output of 16 (being that it is 2016 now)
'However, what I need is to be able to type in the 2 dates.

strString = Reggex(strString, "\[theDate:([^\]]+)\|(.*?)\]", ""&DateDiff("yyyy","$1","$2")&"")

'However, the output in this example, will give me 1 (ONE)
ReplaceChar = strString
End Function
working = "[Busdate]"
testing = "[theDate:1950|2016]"
%>
Working: <%=ReplaceChar(working)%><br />
Non-working: <%=ReplaceChar(testing)%>

Open in new window


I know there has to be a way to do this.
Any idea's?
Comment
Watch Question
Social distance; Wear a mask; Don't touch your face; Wash your hands for 20 seconds
CERTIFIED EXPERT
Top Expert 2014
Commented:
This problem has been solved!
Unlock 1 Answer and 47 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE