php How to strip zero's from month and day date

the code below is grabing dates from my db that I need to use in jquery datepicker.

my problem is that my dates from the db are in the wrong format that my datepicker is accepting.

right out of the db the format is "2010-09-09,2010-09-17,2010-12-05" etc

The datepicker does not like the zero's infront  of the month's or days it prefers the format below:

How can I strip the zero's out of the "arrayy" array only if they exist?


$string =  $dated["start_date"];
$fresh = substr($string, 0, -9); // removes the time and leaves date from stamp



echo "<script>";

echo "var disabledDays = new Array();";

foreach($arrayy as $key=>$value) {
 echo "disabledDays[$key] = \"$value\";";

echo "</script>";

Open in new window

Who is Participating?
leakim971Connect With a Mentor PluritechnicianCommented:
server side :

preg_replace(/-0", "-", $myDates);
    $myDates = "2010-09-09,2010-09-17,2010-12-05";;
    $myDates = preg_replace("/-0/", "-", $myDates);
    print $myDates;

Open in new window

Use (client side) : myDate.replace(/-0/g,"-");

test page :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript">
	var myDates = "2010-09-09,2010-09-17,2010-12-05";
	alert( myDates.replace(/-0/g,"-") );

Open in new window


try this example:

        $TR  = "2010-09-09";
      $st = preg_replace(array('/-0/'), ' ', $TR);
      $st1 = preg_replace(array('/ /'), '-', $st);
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Chris StanyonCommented:
Convert your database date to unix timestamp (strtotime) and then format that using DATE - Y for 4 digit year, n for months without leading zeros, and j for days without leading zeros.

echo date("Y-n-j",strtotime($dated["start_date"]));

Open in new window

In your MySQL : select replace(myDate,"-0","-") as myDate from myTable

test page lol :

select replace("2010-09-09","-0","-") as "myDate" from dual

select replace("2010-09-09,2010-09-17,2010-12-05","-0","-") as "myDate" from dual

Open in new window

Thanks for the points!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.