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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript to Javascript

Status
Not open for further replies.

MONFU

Programmer
Oct 27, 2001
35
MT
Dear All,

I have done some code in VBScript so that if the date is displayed in the 7/7/2002, or 8/8/2002 format for example, I change that in 07/07/2002 and 08/08/2002 respectively. This is so that I can do some validation on the fields. Now I wish to change the code that I will paste here into a Javascript function so that I can use it in more Asp's just by calling this function. Can you please tell me how I can do that since I am a newbie in Javascript.

Here is the VBScript code:-

------------------------------------------------------
DBDate = rs("newsDate")

slash = Instr(DBdate, "/")
strMonth = mid(DBdate, 1, slash-1)
rest = mid(DBdate, slash+1, len(date))

slash2 = Instr(rest, "/")
strDay = mid(rest, 1, slash2-1)
strYear = mid(rest, slash2+1, len(rest))

if strMonth < 10 then
strMonth = &quot;0&quot; & strMonth
end if

if strDay < 10 then
strDay = &quot;0&quot; & strDay
end if

DBDateFormat = strMonth & &quot;/&quot; & strday & &quot;/&quot; & strYear

-------------------------------------------------------

THanks for your help!
 
Direct translation:

var slash = DBdate.indexOf(&quot;/&quot;);
var strMonth = DBdate.substr(0, slash);
var rest = DBdate.substr(slash+1);

var slash2 = rest.indexOf(&quot;/&quot;);
var strDay = rest.substr(0, slash2);
var strYear = rest.substr(slash2+1);

if (strMonth < 10) strMonth = &quot;0&quot; + strMonth

if (strDay < 10) strDay = &quot;0&quot; + strDay

DBDateFormat = strMonth + &quot;/&quot; + strday + &quot;/&quot; + strYear;

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top