array and date format

i want to have

if ship_date is 0000-00-00, then it has to be empty.
if ship_date is 2006-04-21, then it has to be 04/21/2006.

How can i get those results based on the bottom code.


--------------------------------------


$csvquery = 'SELECT * FROM testcsv ';
$result = mysql_query($csvquery) or die("Error encountered ".mysql_error());
$csvData= Array();
$fieldCount=mysql_num_fields($result);
 
for($j=0;$j<$fieldCount;$j++) {
  $csvData[0][$j]=mysql_field_name($result,$j);         
}
             
$i=1;
while($csvrow = mysql_fetch_array($result, MYSQL_NUM)) {
       $csvData[$i++]=$csvrow;
       print_r($csvData);
}


-------------------------------------------------------



Array
(
    [0] => Array
        (
            [0] => order_number
            [1] => LNnumber
            [2] => order_approval_status
            [3] => ship_date
            [4] => tracking_number
        )

    [1] => Array
        (
            [0] => M0101
            [1] => KVTR-6NYLQF
            [2] => 1
            [3] => 2006-04-21
            [4] =>
        )

)
Array
(
    [0] => Array
        (
            [0] => order_number
            [1] => LNnumber
            [2] => order_approval_status
            [3] => ship_date
            [4] => tracking_number
        )

    [1] => Array
        (
            [0] => M0101
            [1] => KVTR-6NYLQF
            [2] => 1
            [3] => 2006-04-21
            [4] =>
        )

    [2] => Array
        (
            [0] => M0102
            [1] => KVTR-6NYLQG
            [2] => 1
            [3] => 0000-00-00
            [4] =>
        )

)
Array
(
    [0] => Array
        (
            [0] => order_number
            [1] => LNnumber
            [2] => order_approval_status
            [3] => ship_date
            [4] => tracking_number
        )

    [1] => Array
        (
            [0] => M0101
            [1] => KVTR-6NYLQF
            [2] => 1
            [3] => 2006-04-21
            [4] =>
        )

    [2] => Array
        (
            [0] => M0102
            [1] => KVTR-6NYLQG
            [2] => 1
            [3] => 0000-00-00
            [4] =>
        )

    [3] => Array
        (
            [0] => M0103
            [1] => KVTR-6NYLQH
            [2] => 4
            [3] => 0000-00-00
            [4] =>
        )

)
bbvicAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Richard QuadlingSenior Software DeveloperCommented:
<?php
if ('0000-00-00' != $date_from_csv)
 {
 $date_from_csv = date('d/m/Y', strtotime($date_from_csv));
 }
else
 {
 $date_from_csv = '';
 }


or

$date_from_csv = ('0000-00-00' != $date_from_csv) ? date('d/m/Y', strtotime($date_from_csv)) : '';

0
Richard QuadlingSenior Software DeveloperCommented:
Oops sorry. You want funny american formatted date!

How on earth do you sort by dates? Wierd.

Anyway!

<?php
if ('0000-00-00' != $date_from_csv)
 {
 $date_from_csv = date('m/d/Y', strtotime($date_from_csv));
 }
else
 {
 $date_from_csv = '';
 }
?>


or
<?php
$date_from_csv = ('0000-00-00' != $date_from_csv) ? date('m/d/Y', strtotime($date_from_csv)) : '';
?>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bbvicAuthor Commented:
thanks
0
tolgaongCommented:
a solution with mysql query

$csvquery="SELECT
order_number,
LNnumber,
order_approval_status,
IF(left(ship_date,4)='0000','',date_format(ship_date,'%m/%d/%Y')) as ship_date
FROM `testcsv` ";
$result = mysql_query($csvquery) or die("Error encountered ".mysql_error());
$csvData= Array();
$fieldCount=mysql_num_fields($result);
 
for($j=0;$j<$fieldCount;$j++) {
  $csvData[0][$j]=mysql_field_name($result,$j);        
      }
           
$i=1;
while($csvrow = mysql_fetch_array($result, MYSQL_NUM)) {
      $csvData[$i++]=$csvrow;
      }
echo "<pre>";
print_r($csvData);
echo "</pre>";
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

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.