VBS string and date operation functions

Source: Internet
Author: User
Recently, I used date format conversion when writing asp programs. Because different databases have different requirements on date formats, I have found some relevant information here. I hope it will be helpful to you. If you have any questions, please leave a message, thank you! 1. Asc (x), Chr (x): conversion character, escape code
2. Filter: Search for a specific string in the string array
Format: v = filter (x, s [, include [, compare])
Instance:
Dim x () = {"kjwang", "wangkj", "peter "}
Dim v
V = filter (x, "kj") 'result v (0) = "kjwang", v (1) = "wangkj"
V = filter (x, "kj", false) 'result v (0) = "peter"
V = filter (x, "kj", true, vbTextCompare) 'case-insensitive search
3. InStr: search for the string position (reverse Rev: Search for the string)
Format:
V = instr (x, y) 'returns the position where the y string appears starting from 1st characters in string x.
V = instr (n, x, y) 'specifies the position where the y string appears from the nth character of string x.
Format:
V = Limit Rev (x, s [, n [, Compare])
4. Join: connect strings
Format: v = join (x [, d]) 'd is a separator
5. Len (x): calculates the length of string x.
Format: v = len (x)
6. Left (x, n): returns n characters (corresponding to Right (x, n) on the Left of string x ))
7. Mid: read characters in the middle of string x
Format: v = mid (x, n, m)
8. LTrim (x), RTim (x), Trim (x) Go to blank characters
9. Replace: String replacement
Format: v = Replace (x, s, r)
Instance: x = "I saw a saw"
V = replace (x, "saw", "so") 'v = "I so a so"
10. Split: string segmentation
Format: v = split (s [, d])
Instance: v = split ("vb.net, iis6.0, asp.net ",",")
'Result v (0) = "vb.net", v (1) = "iis6.0", v (2) = "asp.net"
11. StrReverse: reverse string
Instance: v = strreverse ("kjwang") 'v = "gnawjk"
12. UCase (x) and LCase (x): Change the case sensitivity of English letters.
Example: x = "hello, VB Chinese! "
V = UCase (x) 'v = "HELLO, VB Chinese! "
'Date-related:
1. Retrieve the date and time
1) DateValue (x), TimeValue (x)
Format: v = DateValue (x): The retrieved "date" section.
V = timevalue (x) 'class
2) Year (x), Month (x), Day (x)
Format: v = Year (x)
V = Month (x)
V = Day (x)
Hour (x), Minute (x), Second (x): Minute, Second
3) DateSerial (Y, M, D): combines the year, month, and day as the date
Instance: Dim v
V = DateSerial (, 5) 'v = 1996/10/5
TimeSerial (H, M, S): the merging time, minute, and second
2. Now: reads the system date and time
Format: v = now
3. Timer: the number of seconds that have elapsed since 12:00:00 AM.
Format: v = timer
4. DatePart (p, x): obtains the values of the year, month, day, and other parts.
Instance: Dim X = #2/10/1996 16:45:30 #
V = DatePart ("yyyy", X) 'v = 1996
V = DatePart ("m", X) 'v = February
V = DatePart ("d", X) 'v = 10
V = DatePart ("h", X) 'v = 16 hours
V = DatePart ("n", X) 'v = 45
V = DatePart ("s", X) 'v = 30 seconds
V = DatePart ("q", X) 'v = Season 1 (first season, spring)
V = DatePart ("y", X) 'v = 41 days (1996 days of January 1, 41st)
V = DatePart ("ww", X) 'v = 6 weeks (1996 weeks of 6th)
V = DatePart ("w", X) 'v = 7 (6th days of week 1, that is, Saturday)
5. DateAdd (p, n, x): the new date and time after the plus or minus time
Format: v = DateAdd (p, n, x) 'P value is the same as above: "yyyy", "m", etc.
Instance: Dim x = #1/31/1996 16:45:30 #
V = dateadd ("yyyy",-3, x) 'minus 3 years, v = 16:45:30
6. DateDiff (p, x1, x2): calculate the difference between the two Date and time. The p value is the same as above.
Instance: dim x1 = #12/31/1996 16:45:30 #
X2 = #2/10/1997 9:30:50 #
V = datediff ("yyyy", x1, x2) 'v = 1 year
7. FormatDateTime: format the date and time
Format: v = formatdateyime (x [, Date Format])
Date Format values: DateFormat. GeneralDate, DateFormat. LongDate,
DateFotmat. interval date, DateFormat. LongTime, DateFormat. interval time
8. MonthName: returns the name of the month.
Instance: v = monthname (5) 'v = "May"
9. WeekDayName: the name of the returned Week.

For more articles about VBS string and date-related functions, refer to PHP!

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.