The JavaScript is loosely typed. Database files are not. If you put the text into a Boolean database column or a Boolean of date/time column, then you have an error.
For the "most part" a problem, except for date/time . It does not correspond to the JavaScript Date Object. So, we have to tear Date apart and rebuild it from scratch. If we don ' t, then we get a type mismatch error.
Take a look at the snippet below. (It's not part of my lesson, but I want you to look at it anyway.) Please notice DateTime .
objConn.Open (strconnect)
sql = INSERT into folovisit (sessionid,visittime) "
sql+=" Values (' + Session.SessionID + "', #" + DateTime + "#);"
objConn.Execute (SQL)
DateTime has to is in a very particular format: #mm/dd/yyyy hh:mm:ss [a|p]m# as your OK know new Date () doesn ' t even come close to this format. We'll fix this in the script below.
Get started:
Below is the script for Lesson 20.
<% @LANGUAGE = "JavaScript"%> <script language= "VBScript" runat= "Server" > Dim vbtime,vbdate,vbdatetime Vbtime = time & "" Vbdate = Date & "" Vbdatetime = Date & "" & Time </SCRIPT> <% function what Timeisit () {var m=new Date () var minute=m.getminutes () var second=m.getseconds () var ampm=false if (minute >=0 & amp;& minute < {minute= ("0" + Minute)} if (second >= 0 && second <) {second= ("0" + SE COND)} var hours=m.gethours () if (Hours >) {ampm=true hours=hours-12} if (hours==12) {ampm=true} if ( Hours = = 0) {hours=hours+12 ampm=false} if (ampm) {ampm= "PM"} else {ampm= "AM"} var mytime=hours + ":" +
Minute + ":" + second + ampm return mytime;
var DateTime = new Date ();
var Month = (Datetime.getmonth () + 1) + "/";
var day = datetime.getdate () + "/";
var year = Datetime.getfullyear ();
var justthedate = Month + day + year;
var justthetime = Whattimeisit (); var DateTime = Month + day + year + "" + whattimeisit ();
Response.Write ("
Click here to run the script in a new window.
Living on VBScript time:
The other way to solve the problem are to use the VBScript date and time Objects. What can I say? If you can ' t beat ' em, steal from ' em!
Time for a Tangent:
If all are want to be store
new Date ()
exactly as-is in your database then does so in a text or memo Colu Mn. The disadvantage of using this tactic was that SQL cannot sort items correctly by date and time. Instead, they ' ll be sorted by alphabetical order.
Final Thoughts:
That ' s's end of the lesson plan. I have received messages to the world. Thank for your kind words. If you have questions or comments your can click onto the link for the home page and then there ' a link to contact me.