php - Change date format (keep "variables") -


i'm trying change dateformat according country user using.

currently i've come this:

function format_date($date = '', $format=null)     {         if($date == "0000-00-00") return "";         $datetime = new datetime($date);                 if(!$format){                     $ci =& get_instance();                     switch($ci->session->userdata("country")){                         case 3:                             $format = "d-m-y h:i:s";                         break;                         default:                             $format = "y-m-d h:i:s";                         break;                     }                 }                 return $datetime->format($format);     } 

but if format of $date is:

2013-03-15 15:50:30

i want output be:

15-03-2013 15:50:30

and if format is:

2013-03-15

i want output be:

15-03-2013

instead of:

15-03-2013 00:00:00

if wanter argument format is should force format.

edit:

sometimes need 2013-04-12 16:52.

and should able format here too:/

use mkdate this

/* 2013-04-18 */ echo date("y-m-d", mktime(0, 0, 0, 12, 30, 1997));  /* 18-04-2013 */ echo date("d-m-y", mktime(0, 0, 0, 12, 30, 1997)); 

more example find on php.net page


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -