VBScript function Refresher Course

Source: Internet
Author: User
Tags add date expression function definition functions numeric value string time interval
vbscript| function |vbscript| function recently when looking at the CSDN forum, I found that many people are still asking basic ASP questions, and a great deal of it revolves around some of the commonly used VBScript functions. Here I would like to point to a few commonly used functions. We don't need to recite the function definition, but we need to know this function and think about it when necessary.

1. How do I add a date to a date?

DATEADD (interval, number, date)

Parameters

Interval Required option. A string expression that represents the time interval to add.
Number must be selected. Numeric expression that represents the number of time intervals to add. Numeric expressions can be positive (get future dates) or negative numbers (get past dates).
Date Required option. Variant or text to be added to the interval representation date.

The interval parameter can have the following values:

YYYY years
Q Quarter
M month
Y number of days in a year
D-Day
W Number of days in a week
WW Week
H hours
N Minutes
s seconds

Example: Date= DateAdd ("M", 1, "31-01-2004") results from February 31, 2004? Oh, no, it's February 29, 2004, DATEADD () will not return the wrong date

2. How do I get the time interval of two dates?

DateDiff (interval, date1, date2)

Parameters

Interval Required option. A string expression represents the time interval between Date1 and Date2.
Date1, date2 required option. An expression of a date. Two dates used for the calculation.

The interval parameter can have the following values:

Set description
YYYY years
Q Quarter
N months
Y number of days in a year
D-Day
W Number of days in a week
WW Week
H hours
M minutes
s seconds


Example: Diffdate=datediff ("D", Now, "31-01-2004")

3. How do I accurately calculate my results?

FormatNumber (expression [, numdigitsafterdecimal [, IncludeLeadingDigit [, UseParensForNegativeNumbers [, GroupDigits] ]]] )

Parameters
Expression required option. The expression to be formatted.
Numdigitsafterdecimal can be selected. A numeric value indicating the number of digits displayed to the right of the decimal point. The default value is-1, which indicates that the computer's locale is being used.
IncludeLeadingDigit can be selected. A three-state constant that indicates whether to display a decimal value of 0 in the front.
UseParensForNegativeNumbers can be selected. A three-state constant that indicates whether negative values are placed in parentheses.
GroupDigits can be selected. A three-state constant that indicates whether numbers are grouped by using the numeric grouping symbols specified in the computer locale.
Set up
The IncludeLeadingDigit, useparensfornegativenumbers, and GroupDigits parameters can have the following values:

Constant numerical description
TristateTrue-1 True
Tristatefalse 0 False
TristateUseDefault-2 uses the settings in the computer locale.

Example: Format 1/3 as four decimal places with a format before the decimal point 0 formatnumber (1/3, 4,-1)

4. How do I get the present time, date, year, month, etc?

Time: Now ()
Dates: Date ()
Years: Year (Date ())
Month: Month (Date ())
Days: Day (Date ())
Hours: Hour (now ())
Minutes: Minute (now ())
Seconds: Second (now ())

5, how do I read out from the database of the news title display part?

Left (string, length)

Parameters
string expression whose leftmost character is returned.
The Length numeric expression that indicates the number of characters to return. If 0, returns a 0 length string (""), and returns the entire string if it is greater than or equal to the total number of characters in the string argument
Len (String | varname)

Parameters
Any valid string expression for string. Varname any valid variable names.

Assuming that the news headline is RS ("topic"), we just want to output 10 characters and output all for less than 10 characters, so we write:
<%
If Len (RS ("topic")) >10 Then
Response.Write Left (RS ("topic"), 8 & "..." ' Also not certain 8, how good-looking how to set up, because the back added ... So we cut down some
Else
Reponnse.write RS ("topic")
End If
%>

Students, class:



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.