Posted By

giak on 01/13/10


Tagged

date Switch split


Versions (?)

PHP : form a date with slash or dash


 / Published in: PHP
 

URL: http://www.giacomel.fr

  1. // transforme une date 31/07/2007 en 2007-07-31 et inversemment sans heure
  2. function neo_date_transform ($date, $separator){
  3. switch ($separator) {
  4. case "/":
  5. $split = split("/", $date);
  6. $jour = $split[0];
  7. $mois = $split[1];
  8. $annee = $split[2];
  9. return $date = $annee . "-" . $mois . "-" . $jour;
  10. case "-":
  11. $split = split("-", $date);
  12. $annee = $split[0];
  13. $mois = $split[1];
  14. $jour = substr($split[2], 0, 2); // enleve l'heure
  15. return $date = $jour . "/" . $mois . "/" . $annee;
  16. }
  17. }

Report this snippet  

You need to login to post a comment.