

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

# Funzione DATE\$1DIFF in Amazon QLDB
DATE\$1DIFF

**Importante**  
Avviso di fine del supporto: i clienti esistenti potranno utilizzare Amazon QLDB fino alla fine del supporto, il 31/07/2025. Per ulteriori dettagli, consulta [Migrare un registro Amazon QLDB su Amazon Aurora PostgreSQL](https://aws.amazon.com/blogs/database/migrate-an-amazon-qldb-ledger-to-amazon-aurora-postgresql/).

In Amazon QLDB, usa `DATE_DIFF` la funzione per restituire la differenza tra le parti di data specificate di due determinati timestamp.

## Sintassi


```
DATE_DIFF( datetimepart, timestamp1, timestamp2 )
```

## Argomenti


*datetimepart*  
La parte relativa alla data o all'ora in cui opera la funzione. Questo parametro può essere uno dei seguenti:  
+ `year`
+ `month`
+ `day`
+ `hour`
+ `minute`
+ `second`

*timestamp1*, *timestamp2*  
I due nomi di campo o espressioni del tipo di dati `timestamp` confrontati dalla funzione. Se *timestamp2* è successivo a*timestamp1*, il risultato è positivo. Se *timestamp2* è precedente a*timestamp1*, il risultato è negativo.  
Un valore letterale del timestamp Ion può essere indicato con backticks (). ``...`` Per dettagli sulla formattazione ed esempi di valori di timestamp, consulta [Timestamp](https://amzn.github.io/ion-docs/docs/spec.html#timestamp) nel documento delle specifiche di Amazon Ion.

## Tipo restituito


`int`

## Esempi


```
DATE_DIFF(year, `2010-01-01T`, `2011-01-01T`)            -- 1
DATE_DIFF(year, `2010-12T`, `2011-01T`)                  -- 0 (must be at least 12 months apart to evaluate as a 1 year difference)
DATE_DIFF(month, `2010T`, `2010-05T`)                    -- 4 (2010T is equivalent to 2010-01-01T00:00:00.000Z)
DATE_DIFF(month, `2010T`, `2011T`)                       -- 12
DATE_DIFF(month, `2011T`, `2010T`)                       -- -12
DATE_DIFF(month, `2010-12-31T`, `2011-01-01T`)           -- 0 (must be at least a full month apart to evaluate as a 1 month difference)
DATE_DIFF(day, `2010-01-01T23:00Z`, `2010-01-02T01:00Z`) -- 0 (must be at least 24 hours apart to evaluate as a 1 day difference)

-- Runnable statements
SELECT DATE_DIFF(year, `2010-01-01T`, `2011-01-01T`) FROM << 0 >> -- 1
SELECT DATE_DIFF(month, `2010T`, `2010-05T`) FROM << 0 >>         -- 4
```

## Funzioni correlate

+ [DATE\$1ADD](ql-functions.date_add.md)
+ [EXTRACT](ql-functions.extract.md)
+ [TO\$1STRING](ql-functions.to_string.md)
+ [TO\$1TIMESTAMP](ql-functions.to_timestamp.md)
+ [UTCNOW](ql-functions.utcnow.md)