phpjavascriptjquerydatereorganize

Organize date format with PHP


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?


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