PHP : form a date with slash or dash


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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. }

URL: http://www.giacomel.fr

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.