View Full Version : How is this vbscript written in javascript?

11-15-2005, 12:29 PM
Sorry, abit of a novice.

How would i achieve the same functionality as this vbscript in javascript?

document.write(" ")

i really should spend a little more time learning javascript, but work is so time consuming :rolleyes:

Thanks for any help...

11-15-2005, 02:45 PM
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();
now.getDate() + "/"
+ (now.getMonth() + 1) + "/"
+ now.getFullYear()

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

11-15-2005, 03:52 PM
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.

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...

document.write(" ")

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...

11-15-2005, 04:54 PM
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();
</script>You can then use functions of the date object then, like getHour(), getMonth(), getFullYear(), and so on.

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 :) ]