OVH Cloud OVH Cloud

Probleme de formatage de l'heure

2 réponses
Avatar
_______
Bonjour.
Un script PHP doit remplir une base MySQL à partir d'un fichier texte.
Dans ce fichier se trouve un champ 'Heure' au format HHMM ou HHMMSS. Comment
transformer ce champ au format time de SQL à savoir HH:MM:SS ?
Merci pour votre aide.

2 réponses

Avatar
loufoque
_______ wrote:
Bonjour.
Un script PHP doit remplir une base MySQL à partir d'un fichier texte.
Dans ce fichier se trouve un champ 'Heure' au format HHMM ou HHMMSS. Comment
transformer ce champ au format time de SQL à savoir HH:MM:SS ?
Merci pour votre aide.


$var = 'HHMMSS';
echo substr(0, 4, $var).':'.substr(4, 2, $var).':'.substr(6, 2, $var);
// affiche HH:MM:SS

Avatar
Antoine Dinimant
_______ a écrit:
Bonjour.
Un script PHP doit remplir une base MySQL à partir d'un fichier texte.
Dans ce fichier se trouve un champ 'Heure' au format HHMM ou HHMMSS. Comment
transformer ce champ au format time de SQL à savoir HH:MM:SS ?
Merci pour votre aide.



qqch comme

$heuremysql = chunk_split($heuretxt, 2, ':') ;

ou encore

$heuremysql = wordwrap($heuretxt, 2, ':', TRUE ) ;