Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Script conversion timestamp MYSQL -> timestamp php

6 réponses
Avatar
runan
Bonjour,

Je voudrais savoir si quelqu'un à déjà fait un script
permettand de convertir un timestamp MYSQL vers un timestamp PHP et
inversement ...

Merci

@ +

6 réponses

Avatar
Paul Delannoy
runan a écrit:
Bonjour,

Je voudrais savoir si quelqu'un à déjà fait un script
permettand de convertir un timestamp MYSQL vers un timestamp PHP et
inversement ...


S'il y a une différence, tu m'apprends qq chose là dis donc ;-)

Avatar
Guillaume Bouchard
runan wrote:
Bonjour,

Je voudrais savoir si quelqu'un à déjà fait un script
permettand de convertir un timestamp MYSQL vers un timestamp PHP et
inversement ...


En s'aidant des fonctions de MYSQL qui sont là pour ça :

http://dev.mysql.com/doc/mysql/en/Date_and_time_functions.html

Cependant, ici l'on peux lire:

http://dev.mysql.com/doc/mysql/en/Date_and_time_type_overview.html

"From MySQL 4.1 on, TIMESTAMP is returned as a string with the format
'YYYY-MM-DD HH:MM:SS'. If you want to obtain the value as a number, you
should add +0 to the timestamp column. Different timestamp display
widths are not supported. In MySQL 4.0 and earlier, TIMESTAMP values are
displayed in YYYYMMDDHHMMSS, YYMMDDHHMMSS, YYYYMMDD, or YYMMDD format,
depending on whether M is 14 (or missing), 12, 8, or 6, but allows you
to assign values to TIMESTAMP columns using either strings or numbers."

Donc cela signifie que quoi que tu fasses, tu n'auras pas un script
portable.
Bref, je te deconseille vivement d'utiliser les timestamps mysql, mais
plutot un champs date ou datetime dont le format ne varie pas.

--
Guillaume.

Avatar
Aloatec
Bonjour,

Je voudrais savoir si quelqu'un à déjà fait un script
permettand de convertir un timestamp MYSQL vers un timestamp PHP et
inversement ...


Tu peux utiliser la fonction UNIX_TIMESTAMP(date) d'apèrs la doc, celle-ci
te renvoie un timestamp unix (nombre de seconde depuis le 01/01/1970) a
partir d'une date, datetime ou timestamp mysql.

Autre solution, pourquoi ne pas stocker tes timestamps PHP dans un champ de
type integer unsigned.

Thierry

Avatar
P'tit Marcel
Autre solution, pourquoi ne pas stocker tes timestamps PHP dans un champ de
type integer unsigned.


par ce que cela t'empêche d'utiliser les fonctions mysql liées aux dates
sur la colonne genre year, month, etc.

Avatar
Julian
Paul Delannoy wrote:

runan a écrit:

Bonjour,

Je voudrais savoir si quelqu'un à déjà fait un script
permettand de convertir un timestamp MYSQL vers un timestamp PHP et
inversement ...



S'il y a une différence, tu m'apprends qq chose là dis donc ;-)


je me disais aussi ;)

--
Julian

Qui s'instruit sans agir, laboure sans semer --proverbe arabe


Avatar
runan

Paul Delannoy wrote:

runan a écrit:

Bonjour,

Je voudrais savoir si quelqu'un à déjà fait un script
permettand de convertir un timestamp MYSQL vers un timestamp PHP et
inversement ...




S'il y a une différence, tu m'apprends qq chose là dis donc ;-)



je me disais aussi ;)

Le timestamp unix par de l'année 1970 et est illisible et celui qui est

dans la base mysql (incrémenté lors de l'enregistrement) est lisible. Il
commence par l'année puis mois jour heure. D'où mon problème, ou alors
je n'utilise pas la bonne commande sous Unix pour avoir un timestamp
lisible ....