0

I am retrieving a date from a database in ASP vbscript and want to pass it on to a javascript function (and use it in date format).

I tried converting my date to a CDate in ASP, passing that on to my javascript function and making a javascript out of it by use of the Date(ASPDate). When doing that, I always get the error "missing ) after argument list" since there is a space between the day and the time.

relevant code:

CreateTimeStart(" & dteActualStartTime & ")

function CreateTimeStart(dteActualStartTime){
    timestart = Date(dteActualStartTime);
}   

2 Answers 2

1

Use the Date.parse method:

CreateTimeStart('<%= dteActualStartTime %>');

function CreateTimeStart(dteActualStartTime){
    var timestart = Date.parse(dteActualStartTime);
}

https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/parse

Sign up to request clarification or add additional context in comments.

Comments

1

You can't know the date settings on the client machine, so you can't depend on them to be the same as on your server.

One way around is to pass the amount of miliseconds that passed since January 1st 1970 to create the date instance:

<script type="text/javascript">
    var dteActualStartTime = new Date(<%=(DateDiff("s", "1/1/1970", dteActualStartTime)) * 1000%>);
    alert("date from server: " + dteActualStartTime);
</script>

This way you don't care if the client machine got dd/mm/yyyy, mm/dd/yyyy or anything else - you pass pure number and let the client machine parse it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.