We help IT Professionals succeed at work.

convert yyyy-mm-dd to mm/dd/yyyy in php

prashanth ag
prashanth ag asked
on
Before it was working fine this format getbusinessDays("2015-01-01","2015-12-31",$holidays)

function getbusinessDays($startDate,$endDate,$holidays)
{
$endDate = strtotime($endDate);                                  
$startDate = strtotime($startDate); before
}

i want convert  yyyy-mm-dd to mm/dd/yyyy

function getbusinessDays($startDate,$endDate,$holidays)
{
$endDate = date('mm/dd/yyyy', strtotime($endDate));                  
 $startDate = date('mm/dd/yyyy', strtotime($startDate));
}

but it shows error
Notice: A non well formed numeric value encountered             (i.,e both lines @$endDate & $startDate)
Comment
Watch Question

Full-stack Java Developer
Commented:
Just try

function getbusinessDays($startDate,$endDate,$holidays)
{
$endDate = date("m/d/Y", strtotime($endDate));                  
 $startDate = date("m/d/Y", strtotime($startDate));
}

Open in new window


http://php.net/manual/pl/function.date.php
Most Valuable Expert 2011
Top Expert 2016

Commented:
We have an article here that answers this question and many more about date / time values.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

Going forward, you might want to check the E-E articles, since many of the most common PHP questions are answered there with examples!