| Function |
Syntax |
Description |
Example |
| Now |
Now () |
Obtain the current date and time of the system. |
Dim myvar =Now 'MyvarContains the current date and time. |
| Date |
Date () |
Obtain the current system date |
Dim mydate =Date 'Mydate'Contains the current system date. |
| Time |
Time () |
Obtain the current system time |
Dim mytime =Time 'Returns the current system time. |
| Year |
Year (date) |
Get the year of a given date |
Dim mydate, myyear Mydate = # October 19,196 2 # 'Assign a date.
Myyear =Year (Mydate) 'Myyear'Include1962. |
| Month |
Month (date) |
Returns the month of a given date. |
Dim myvar =Month (Now) 'Myvar contains the number corresponding to the current month. |
| Day |
Day (date) |
Returns the number of the given date. |
Dim myday =Day ("October 19,196 2") 'Myday' includes19. |
| Hour |
Hour (time) |
The hour at which the given time is obtained |
Dim mytime, myhour Mytime = now myhour =Hour (Mytime) 'MyhourContains the value representing the current time. |
| Minute |
Minute (time) |
Returns the number of minutes for a given time. |
Dim myvar Myvar =Minute (Now) |
| Second |
Second (time) |
The number of seconds to obtain the token. |
Dim mysec Mysec =Second (Now) 'MysecContains the number representing the current second. |
| Weekday |
Weekday (date) |
Returns the integer of the given date in the day of the week. 1 indicates Sunday, 2 indicates Monday, and so on. |
Dim mydate, myweekday Mydate = # October 19,196 2 # 'Dispatch date
Myweekday =Weekday (Mydate) 'MyweekdayInclude6. mydateFriday |
| Datediff |
Datediff ("Var", var1, var2) VaR: date or interval factor, which has the following parameters: Yyyy, M, D, WW, week, H, S, secondsVar1: the first date or time Var2: second date or time, later than var1 |
Calculate the interval between two dates or times |
Datediff ("D", date (), #1/1/2005 #) 'Return the number of New Year's Eve before 2005 Datediff ("H", date (), #1/1/2005 #) 'How many hours are there before 2005 New Year's Day? Datediff ("D", #1/1/2003 #, #1/1/2005 #) 'Returns the number of days between two dates. |
| Dateadd |
Datediff ("Var", var1, var2) VaR: date or interval factor: Var1: date or interval multiple Var2: benchmark of date or time |
Add two dates or times |
In the following example, we will add a month to April January 31: Newdate =Dateadd ("M",1,"31-Jan-95")
In this example,DateaddReturn February 28, instead of February 31. IfDateIf the value is January 31, the return value is February 29, because 1996 is a leap year. If the calculation date is before January 1, 100 AD, an error occurs. |
| Formatdatetime |
Formatdatetime (date, vb1_date) |
Convert to short Date Format |
Fromatdatetime (date (), vblongdate) "Displayed in long Date Format |
|
Formatdatetime (date, vblongdate) |
Convert to long Date Format |
|
Formatdatetime (date, vb1_time) |
Convert to short time format |
| |
Formatdatetime (date, vblongtime) |
Convert to long time format |