Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How can VB convert the string date in access into date format and calculate the date?
How can VB convert the string date in access into date format and calculate the date?
VB is already very good at using strings.

Then the application description of ACCESS is as follows:

1: String conversion date format

Class A: CDATE function conversion, which directly converts strings into dates.

Example: print cdate ("11/2017").

Results: 2017-01-01.

Class b: format function conversion

Darken s as a string

S="20 17- 1- 1 "

S=" 1/ 1/20 17 "

Wait for type S, but at least make sure that the S string is the content of the date response. For example, S = "20 17 March 1 day" looks like a date, but it is not the content of the string required by the date.

Example: print format (s, "YYYY-MM-DD")

YYYY is the year, YY is the two-digit year, MM is the two-digit month, and M is the month without the beginning of 0. So is DD. Returns a date format string.

-

Appeal is a date conversion, CDATE is more convenient and the format is more customized. The YEAR () function +MONTH () function =DAY () function is used to obtain the year, month and day corresponding to the character string.

Let's talk about date format comparison, addition and subtraction and so on.

A: dateadd ("class 1", class 2, "date format")

Description: Class 1=M is the calculation month, d is the day and y is the year.

Category 2 is a number, an integer, and cannot have a decimal point, but it can be positive or negative.

Date format, this need not be explained.

For example: dateadd ("m ",1," 2017-01-0/), dateadd ("m ",-1," 201.

Results: 2017-02-012016-12-01

Note: On the date of 20 1 7-01-01,(1) months were added, and the second month was (-1) months, or one month was reduced.

M is replaced by y to become a decreasing year, and d is replaced to reduce the number of days.

B:DateDiff (interval, date 1, date 2)

Interval ={Y, q, m, d, w, h, n, S}

They are year, quarter, month, day, week, hour, minute, second and so on.

For example: datediff ("m ","2016-01","20 17-0 1 ")

Results: 12 months, change to other, such as d=366 days, such as h=8784 hours, such as s=3 1622400 seconds.

Summary:

The Cdate and Format functions are used to convert strings into date formats.

Year (), Month () and Day () get the year, month and day in the string.

DadeAdd () will target date, increase or decrease the specified date value, etc.

DateDiff () gets the time difference between two dates, which is obtained according to the specified parameters.

Format ("2017-1-1","AAAA") is a wonderful function, and the result is the week of the current date, for example, the result is a Chinese result similar to Monday. Of course, this is because our geographical setting is China, and if it is abroad, it is likely to return to English, German and so on.

I wonder if it meets your needs? If you can't or I misunderstood this proposition, please reply to me.