View Full Version : How is this vbscript written in javascript?
Spoons
11-15-2005, 12:29 PM
:confused:
Sorry, abit of a novice.
How would i achieve the same functionality as this vbscript in javascript?
<SCRIPT TYPE="TEXT/VBSCRIPT">
document.write(MonthName(month(#<%=rs("DB_DATE")%>#)))
document.write(" ")
document.write(Year(#<%=rs("DB_DATE")%>#))
</SCRIPT>
i really should spend a little more time learning javascript, but work is so time consuming :rolleyes:
Thanks for any help...
I don't know enough VBScript to offer an authorative reply here, but you can get the month minus one (0-11) with the non-static function Date.getMonth(), and the year (four-digit) with Date.getFullYear(). For example:
// Prints out (for example) "15/11/2005"
var now = new Date();
document.write(
now.getDate() + "/"
+ (now.getMonth() + 1) + "/"
+ now.getFullYear()
);
Spoons
11-15-2005, 03:46 PM
Thanks for the reply.
I probably wasnt very clear about what i was doing in that vbscript.
Basically i was taking a record from a recordset which was in the US date format of mm/dd/yyyy and getting the vbscript to write in in a month year format (no date).
i.e. 03/01/2005 would appear as March 2005 as would 03/25/2005
Ah... if you're dealing with databases, you probably can't. Except in a few special cases, Javascript cannot access data outside its own (X)HTML document.
Spoons
11-15-2005, 04:26 PM
ah no, i don't need the javascript to access the recordsets, i just want it to format the results that the recordsets provide. same as the vbscript example above. bah, sorry if i am kinda confusing...
in the vbscript example i gave, the <%=rs("DB_DATE")%> is my ASP code which provides the date. this is written in html format of something like 03/25/2002
so, once the ASP has run, the previous example script might look like this...
<SCRIPT TYPE="TEXT/VBSCRIPT">
document.write(MonthName(month(#03/25/2002#)))
document.write(" ")
document.write(Year(#03/25/2002#))
</SCRIPT>
and that code above would display on the page as...
March 2002
And i just need to work out how on earth to achieve the same with javascript rather than vbscript since its more crossbrowser compatible...
You can take the "more" out of that last sentence :) I see what you mean. Try this:
<script type="text/javascript">
var then = new Date();
then.setTime(Date.parse("<%=rs("DB_DATE")%>"));
</script>You can then use functions of the date object then, like getHour(), getMonth(), getFullYear(), and so on.
Spoons
11-15-2005, 05:16 PM
thanks, i shall give it a try... much appreciated
[edit: and yeah... heh hehe... no need for the "more" eh :) ]
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.