« MySQL/Types de données » : différence entre les versions

Contenu supprimé Contenu ajouté
Aucun résumé des modifications
Ligne 21 :
 
== DATE ==
Il existe trois types pour stocker des dates : <code>DATETIME</code>, <code>DATE</code>, et <code>TIMESTAMP</code>.
Out of the three types DATETIME, DATE, and TIMESTAMP, the DATE type is used when you need only a date value, without a time part.
MySQL retrieves and displays DATE values in 'YYYY-MM-DD' format.
The DATETIME type is used when you need values that contain both date and time information.
The difference between DATETIME and TIMESTAMP is that the TIMESTAMP range is limited to 1970-2037 (see below).
 
MySQL récupère et affiche les dates au format "AAAA-MM-JJ" (plus pratique pour les classer de gauche à droite).
TIME can be used to only store the time of day (HH:MM:SS), without the date. It can also be used to represent a time interval (for example: -02:00:00 for "two hours in the past"). Range: '-838:59:59' => '838:59:59'.
 
<code>DATETIME</code> est utilisé quand les valeurs doivent contenir l'heure en plus du jour.
YEAR can be used to store the year number only.
 
La différente entre <code>DATETIME</code> et <code>TIMESTAMP</code> est que la taille des <code>TIMESTAMP</code> est limitée aux années 1970-2037.
 
Le type <code>TIME</code> peut stocker les heures du jour (HH:MM:SS) sans date. Il peut aussi représenter une période de temps (ex : -02:00:00 pour deux heures avant). Limité entre '-838:59:59' et '838:59:59'.
If you manipulate dates, you have to specify the actual date, not only the time - that is, MySQL will not automagically use today as the current date. On the contrary, MySQL will even interpret the HH:MM:SS time as a YY:MM:DD value, which will probably be invalid.
 
<code>YEAR</code> peut stocker des années.
 
 
The following examples show the precise date range for Unix-based timestamps, which starts at the Unix Epoch and stops just before the first new year before the <math>2^{31}-1</math> usual limit (2038).
Pour manipuler des dates, il faut préciser un jour et pas seulement une heure, car pourrait interpréter "HH:MM:SS" comme une valeur "YY:MM:DD".
 
 
Les exemples suivant montrent la plage de date précise pour les temps Unix, démarrant à l'époque Unix jusqu'à 2038 (<math>2^{31}-1</math>).
mysql> SET time_zone = '+00:00'; -- GMT
Query OK, 0 rows affected (0.00 sec)