0

I have a PDO statement, thus. The data is coming from a SQL Server database:

//Get full record from form108 database
$data = $con->prepare("SELECT CONVERT(varchar, p.WorkBeginDate, 101), * FROM Employee AS e 
INNER JOIN EmployeeProjectInfo AS p ON e.empUIN = p.empUIN WHERE e.empUIN = :empuin AND   
p.UID = :uid");
$input = array('empuin'=>$_SESSION['UIN'],'uid'=>$_SESSION['ID']);
$data->execute($input);

Everything displays fine except the date. Instead of the desired format, mm/dd/yyyy, I get yyyy-mm-dd. My hope was that the CONVERT() function would work like the DATE_FORMAT() function in MySQL. The data type in the database is date. What am I doing wrong?

1
  • date is stored as yyyy-mm-dd. Why do you assume that the application or the database know that your desired format is mm/dd/yyyy? Commented Dec 12, 2013 at 15:05

1 Answer 1

1

Theres nothing wrong... all you have to do is change it to the previous format. Here's a very basic example:

$mydate = $result['dateField'];
echo date('m/d/Y', strtotime($mydate)); //prints: 12/25/2013
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, that did work. Is there no way to do it within the query? In MySQL, I've used the DATE_FORMAT function with success. I guess it doesn't work the same way in MSSQL?
I dont know much about mssql but ive found something useful: mysqltomssql.blogspot.com.br/2011/04/dateformat-syntax.html and sql-server-helper.com/tips/date-formats.aspx ... hope it help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.