JavaScript ASP Tutorial Date related _asp basics

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.