Web Analytics Made Easy -
StatCounter I need translation from VBscript to Javascript - CodingForum

Announcement

Collapse
No announcement yet.

I need translation from VBscript to Javascript

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • I need translation from VBscript to Javascript

    i need a code to add a specified number of days to a specified date.
    i've looked but what i got was a VSscript and date is fixed into the code. I need it to work on the date that is entered by the user.

    the VBscript code is something like this
    Code:
    newDate = DateAdd("d",1,"31-01-2000")
    i need it to work like this
    Code:
    var dinterval = document.form1.interval.value;
    var dstart = document.form1.start.value;
    newDate= DateAdd("d",dinterval,dstart);
    i dont know if it is even possible to do that. i havent seen one like it in the internet.

    IF you could help me to tweak the code so it works that way, i will be very grateful!
    Thanks!
    PS. Please tell me if it is impossible so i can try looking for another way.

  • #2
    I don't think it can be done in one statement like that but it can be done in two:

    Code:
    newDate = new Date(dstart);
    newDate.setDate(newDate.getDate()+dinterval);
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

    Comment


    • #3
      i think i've seen something like that before.
      i'm more worried that the format of the date that will be inputted wont be recognized as a date. the format i want is mm-dd-yy. I have a script that gets the no. of days between 2 dates and it involves converting the date (string) into milliseconds and then into days.
      Could you expound some more? I really don't know how to take it from there.
      I tried that and added document.form1.answer.value=newDate; and i think that was wrong. XD. Sorry im a noob.
      THanks

      Comment


      • #4
        To validate that the date is entered in the format you want use:

        Code:
        if(!'/^(0?[1-9]|1[0-2])[\/\.- ](0?[1-9]|[12][0-9]|3[01])[\/\.- ](19|20)\d{2}$/'.test(dstart))
        alert('date is not in the right format');
        Stephen
        Learn Modern JavaScript - http://javascriptexample.net/
        Helping others to solve their computer problem at http://www.felgall.com/

        Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

        Comment

        Working...
        X