Results 1 to 7 of 7

Thread: How is this vbscript written in javascript?

  1. #1
    Join Date
    Oct 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How is this vbscript written in javascript?


    Sorry, abit of a novice.

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

    Code:
    <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

    Thanks for any help...

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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:
    Code:
    // Prints out (for example) "15/11/2005"
    var now = new Date();
    document.write(
      now.getDate() + "/"
      + (now.getMonth() + 1) + "/"
      + now.getFullYear()
    );
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Oct 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Oct 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

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

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You can take the "more" out of that last sentence I see what you mean. Try this:
    Code:
    <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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Oct 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks, i shall give it a try... much appreciated

    [edit: and yeah... heh hehe... no need for the "more" eh ]

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •