Restituisce la parte specificata di una data determinata.
Sintassi
DatePart(interval, date)
Argomenti:
Tabella 11-11 Valori dell'argomento interval
| Impostazione | Descrizione |
|---|---|
| yyyy | Anno |
| q | Trimestre |
| m | Month |
| d | Day |
| w | Giorno feriale |
| h | Hour |
| n | Minute |
| s | Second |
Formati di data supportati:
MM-DD-YYYYMM/DD/YYYYDD-MM-YYYYDD/MM/YYYYYYYY-MM-DDYYYY/MM/DDFormato di ora supportato
hh:mm:ss
Note
È possibile utilizzare la funzione DatePart per calcolare una data e restituire un intervallo di tempo specifico. Ad esempio, è possibile utilizzare DatePart per calcolare il giorno della settimana o l'ora corrente.
In questi esempi viene usata una data e, mediante la funzione DatePart, viene visualizzato il corrispondente trimestre dell'anno.
Esempio 1
Function GetQuarter(TheDate)
GetQuarter = DatePart("q", TheDate)
End Function
Esempio 2
Dim MyDate, YearPart
MyDate = "21/01/2025"
YearPart = DatePart("yyyy", MyDate)
'Output: 2025
Esempio 3
Dim MyDate, MonthPart
MyDate = "21/01/2025"
MonthPart = DatePart("m", MyDate)
'Output: MonthPart contains 1 (January)
Esempio 4
Dim MyDate, DayPart
MyDate = "21/01/2025"
DayPart = DatePart("d", MyDate)
'Output: 21
Esempio 5
Dim MyDate, HourPart
MyDate = "21/01/2025 14:30:00" ' Includes time component.
HourPart = DatePart("h", MyDate)
'Output: 14 (2 PM)
Esempio 6
Dim MyDate, MinutePart
MyDate = "21/01/2025 14:30:00"
MinutePart = DatePart("n", MyDate)
'Output: 30
Esempio 7
Dim MyDate, SecondPart
MyDate = "21/01/2025 14:30:00" ' Includes time component.
SecondPart = DatePart("s", MyDate) ' Returns the second part of the date.
'Output: 0