Aller au contenu

Calcule la différence entre deux horodatages et renvoie le résultat sous forme d’INTERVAL.

func.timestamp_diff(<timestamp1>, <timestamp2>)
func.timestamp_diff(func.to_timestamp('2025-02-01'), func.to_timestamp('2025-01-01'))
┌────────────────────────────────────────────────────────────────────────────────────────┐
│ func.timestamp_diff(func.to_timestamp('2025-02-01'), func.to_timestamp('2025-01-01')) │
├────────────────────────────────────────────────────────────────────────────────────────┤
│ 744:00:00 │
└────────────────────────────────────────────────────────────────────────────────────────┘
TIMESTAMP_DIFF(<timestamp1>, <timestamp2>)

INTERVAL (au format hours:minutes:seconds).

Cet exemple montre que l’écart entre le 1er février 2025 et le 1er janvier 2025 est de 744 heures, soit 31 jours :

SELECT TIMESTAMP_DIFF('2025-02-01'::TIMESTAMP, '2025-01-01'::TIMESTAMP);
┌──────────────────────────────────────────────────────────────────┐
│ timestamp_diff('2025-02-01'::TIMESTAMP, '2025-01-01'::TIMESTAMP) │
├──────────────────────────────────────────────────────────────────┤
│ 744:00:00 │
└──────────────────────────────────────────────────────────────────┘