Sqlserver
 sql >> Base de données >  >> RDS >> Sqlserver

Obtenir une liste des fuseaux horaires pris en charge dans SQL Server (T-SQL)

SQL Server fournit le sys.time_zone_info vue de configuration à l'échelle du serveur pour renvoyer une liste des fuseaux horaires pris en charge.

Vous pouvez les récupérer avec un simple SELECT déclaration.

Exemple

L'exécution de l'instruction suivante renvoie tous les fuseaux horaires pris en charge.

SELECT * FROM sys.time_zone_info;

Cela renvoie 139 lignes sur mon système.

Vous pouvez affiner les résultats avec un WHERE clause. Si vous n'êtes pas sûr du nom du fuseau horaire, vous pouvez toujours utiliser le LIKE clause avec des caractères génériques.

SELECT * FROM sys.time_zone_info
WHERE name LIKE '%Europe%';

Résultat :

+--------------------------------+----------------------+--------------------+
| name                           | current_utc_offset   | is_currently_dst   |
|--------------------------------+----------------------+--------------------|
| W. Europe Standard Time        | +02:00               | 1                  |
| Central Europe Standard Time   | +02:00               | 1                  |
| Central European Standard Time | +02:00               | 1                  |
| E. Europe Standard Time        | +03:00               | 1                  |
+--------------------------------+----------------------+--------------------+

Si vous vous demandez ce que le is_currently_dst la colonne est pour, elle précise si le fuseau horaire observe ou non actuellement l'heure d'été (1 si c'est le cas, 0 si ce n'est pas le cas).

Par conséquent, vous pouvez également effectuer une recherche pour voir quels fuseaux horaires observent l'heure d'été.

SELECT
  name,
  current_utc_offset
FROM sys.time_zone_info
WHERE is_currently_dst = 1;

Voici le résultat que j'ai obtenu au moment où j'ai exécuté cette requête :

+--------------------------------+----------------------+
| name                           | current_utc_offset   |
|--------------------------------+----------------------|
| Aleutian Standard Time         | -09:00               |
| Alaskan Standard Time          | -08:00               |
| Pacific Standard Time (Mexico) | -07:00               |
| Pacific Standard Time          | -07:00               |
| Mountain Standard Time         | -06:00               |
| Central Standard Time          | -05:00               |
| Easter Island Standard Time    | -05:00               |
| Eastern Standard Time          | -04:00               |
| Haiti Standard Time            | -04:00               |
| Cuba Standard Time             | -04:00               |
| US Eastern Standard Time       | -04:00               |
| Turks And Caicos Standard Time | -04:00               |
| Atlantic Standard Time         | -03:00               |
| Pacific SA Standard Time       | -03:00               |
| Newfoundland Standard Time     | -02:30               |
| Greenland Standard Time        | -02:00               |
| Saint Pierre Standard Time     | -02:00               |
| Mid-Atlantic Standard Time     | -01:00               |
| Azores Standard Time           | +00:00               |
| GMT Standard Time              | +01:00               |
| Morocco Standard Time          | +01:00               |
| W. Europe Standard Time        | +02:00               |
| Central Europe Standard Time   | +02:00               |
| Romance Standard Time          | +02:00               |
| Central European Standard Time | +02:00               |
| Jordan Standard Time           | +03:00               |
| GTB Standard Time              | +03:00               |
| Middle East Standard Time      | +03:00               |
| E. Europe Standard Time        | +03:00               |
| Syria Standard Time            | +03:00               |
| West Bank Standard Time        | +03:00               |
| FLE Standard Time              | +03:00               |
| Israel Standard Time           | +03:00               |
| Iran Standard Time             | +04:30               |
| Cen. Australia Standard Time   | +10:30               |
| AUS Eastern Standard Time      | +11:00               |
| Tasmania Standard Time         | +11:00               |
| Lord Howe Standard Time        | +11:00               |
| Norfolk Standard Time          | +12:00               |
| New Zealand Standard Time      | +13:00               |
| Kamchatka Standard Time        | +13:00               |
| Chatham Islands Standard Time  | +13:45               |
| Samoa Standard Time            | +14:00               |
+--------------------------------+----------------------+

Vous pouvez également obtenir le fuseau horaire de votre propre serveur et le recouper avec l'entrée correspondante dans cette liste si vous le souhaitez.