Question

there is any way to organize a date echoed from a datepicker from the last page?

Like this:

I recieve in this format: 2013, 06, 24

And i want this format: 24/06/2013

This is possible?

Était-ce utile?

La solution

If you're referring to getting it in that format from the client side, then When you create your datepicker you can do this:

$( ".selector" ).datepicker({ dateFormat: "dd/mm/yy" });

source: jQuery datepicker documentation

if you want to do it server-side in php after you've received the string, you can do:

$datefields = explode(', ', $dateString);
echo $datefields[2] . '/' . $datefields[1] . '/' . $datefields[0];

I used explode() instead of split() because split() is deprecated and we don't need the full power of preg_split() here either.

source: php explode() documentation

Autres conseils

You could do it like this...

$date = "2013, 06, 24";
$date = str_replace(", ","-",$date);

$date = date('d/m/Y', strtotime($date));

But you never mention which language you wanna do it in?

You have both php and javascript as tags, so how are we supposed to know how exactly you wanna do it.

you could do this using the date-functions that php/js offers or you could go for regular expressions which would be if you are sure you receive a valid format and just want to reformat it:

/(\d{4}), (\d{2}), (\d{2})/ and replace with $3/$2/$1. Would be done in php using preg_replace("/(\d{4}), (\d{2}), (\d{2})/", '$3/$2/$1', "2013, 06, 24");

If it's always the format 'yyyy, mm, dd' you can use:

var mydate = '2013, 06, 24'
               .replace(/\s+/g,'')
               .split(',')
               .reverse()
               .join('/'); //=> '24/06/2013'
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top