[Finishing Version] ASP Common built-in functions

Source: Internet
Author: User
Tags date chr current time date1 datetime functions integer time interval
Function

function, which is a function block encapsulated in the language, to facilitate the user's invocation. For example, "Now" in VBScript is a function that shows the current date and time. As for the specific reason for the display, the language is determined by the kernel, the user only need to understand that "now" is used to show the date time. So, what other functions does VBScript have in our current contact?

1, Date/Time function
These functions include the display of the year, month, day, time, minutes, seconds, week, and so on.

(1) Now function: Returns the current date and time value according to the date and time set by the computer system. Use the method now ();

(2) Date function: Returns only the date value set by the current computer system. How to use: Date ();

(3) Time function: Returns only the value set by the current computer system. How to use: Time ();

(4) The Year function: Returns an Integer that represents an age. How to: Year (date), where the date parameter is any parameter that can represent a date, such as "date ()" to represent an integer that extracts "years" from the date from "date ()".
In addition, you can apply this: "Year (#520, 2006#)" represents an integer value that extracts "years" from May 20, 2006. On the "520,2006", you can also use the "5-20-2006", "5/20/2006" and other forms of performance, that is, "one day a month" and "one year" combination. Also note that use ' # ' is included to represent date values.

(5) Month function: Returns an integer value between 1 and 12 representing the month of the year. How to use: Month (date). The description of the parameter date is the same as the year function. But pay attention to the correctness of the date, such as "#13 -31-2006#", there is no "13" month, it must be wrong.

(6) Day function: Returns an integer value between 1 and 31 that represents one of the days of the one month. Use Method: Day (date). The description of the parameter date is the same as the year function. Also pay attention to the correctness of the date, such as "#2 -30-2006#" where the "2" month definition of "30" Day is wrong.

(7) Hour function: Returns an integer value between 0 and 23 that represents an hour of the day. How to use: Hour (time). Where the parameter time is any expression that can represent an hour. For example, "Hour (time)" means an integer that extracts "hours" from the period derived from "times ()". Similarly, parameter time can also apply "hour (#11:45:50#)" to indicate that the current number of hours is extracted from 45 "50" Seconds from "11". Of course, the time defined should conform to the specification of the time.

(8) Minute function: Returns an integer value between 0 and 59 that represents a minute in an hour. How to use: Minute (time). The description of the time parameter is the same as the hour function.

(9) Second function: Returns an integer value between 0 and 59 that represents a second in a minute. How to use: Second (time). The description of the time parameter is the same as the hour function.

(Ten) Weekday function: Returns an integer that is one day of the one week. How to use: Weekday (date). The description of the parameter date is the same as the year function. The function returns a value of "1" to "7", representing "Sunday", "Monday" respectively ... "Saturday". For example, when the return value is "4", it means "Wednesday."

(one) WeekdayName function: Returns a string that is specific to the day of the one week. The relative weekday function translates "Day of the Week", using the method: WeekdayName (Weekday). The parameter weekday the value of the day of the week. For example, "WeekdayName (weekday)" means that the current is "Day of the week." Because "date ()" represents the current time, weekday (date ()) represents an integer that is specific to the day of the week.

Of course the WeekdayName function eventually displays the string content also related to the current operating system language, such as Chinese operating system will display the "Monday" of this type of characters, while the English operating system is displayed as "Mon" (Monday shorthand).

In addition, there are some computational functions about time intervals in VBScript:

(1) DateAdd function: Returns the date and time of the specified time interval. You can calculate a new date or time that is many years apart, or a few months apart, or a few hours apart. How to use: DateAdd (interval,number,date).

Where the parameter interval represents the time interval unit that needs to be added. It is expressed in the form of a string, for example, "yyyy" for the year, "Q" For the quarter, "M" for the month, "D" for the number of days, "WW" for the number of weeks, "H" for the number of hours, "n" for minutes, "s" for the number of seconds.

The number of parameters indicates how many time intervals were added. It is expressed in numerical form and can be negative. The parameter date requires the correct format for the date and time.

For example, DATEADD ("D", 100, "2006-5-20") means the date value of the 100 days after May 20, 2006:2006-8-28. Another example DATEADD ("H",-12, "2005-5-2010:00:00") represents the 12-hour datetime before 10 o'clock in the morning May 20, 2005:2005-5-1922:00:00.

(2) DateDiff function: Returns the interval between two date and time. You can calculate the age, number of hours, and so on, two dates apart. How to use: DateDiff (INTERVAL,DATE1,DATE2).

The parameter interval and the DATEADD function have the same description of the interval parameter, and the Date1 and Date2 parameters are two date times compared to each other. In addition, when the date1 datetime value is greater than Date2, it is displayed as a negative number.

For example, DateDiff ("yyyy", "1982-7-18", date) indicates how many years has it been since someone's birth. For example, DateDiff ("D", "1982-7-18", "2062-7-18") calculated the number of days after 80 years: 29220.

2, String handler function

In the functional processing of a script, some of the strings are usually decorated with some modification. For example, filter out the sensitive words in the string to meet the requirements of the final display, or, for example, a longer string, you need to extract the first few words characters.

(1) ASC function: Returns the ANSI character code corresponding to the first letter in the string. Use Method: ASC (String). Where string parameters represent strings.

(2) CHR function: Returns the character corresponding to the ANSI character code specified. How to use: Chr (Chrcode). The parameter chrcode is the associated identification number. The functions of the function and the ASC function form the corresponding.

For example, ASC ("A") represents the ANSI character "97" of the lowercase letter "a", and the same Chr (97) denotes "lowercase a". In addition, the CHR (chrcode) parameter chrcode a number from 0 to 31 indicates an ASCII code that is not printable. For example, "Chr (10)" means line breaks, "Chr (13)" means carriage returns, and so on, which is often used in the conversion of input and display formats.



Related Article

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.