mySQL Extract Query to give date as MMDDYY

I have an PHP script to extract to a CSV. I am trying to get the date to come out as MMDDYY. When I run it now I get the date and time.

Example:   2015-08-28 09:39:27.
I want this to be 082815

This is my query:
   $select_table=$mysqli->query("SELECT tom.OrderNumber,tom.PartNumber,tom.DateOrdered,4 as HardCodedField,tom.QtyOrdered,tom.LineItemApproved FROM `tblorderlineitem` tom ");

Can I use something in my select statement to make date come out this way?
allenkentAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Julian HansenCommented:
You can use the MySQL CONCAT() function combined with the Date Functions MONTH(), DAY() and YEAR()
CONCAT() https://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat
MONTH() https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_month
DAY() https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_day
YEAR() https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_year
$query = <<< QUERY
SELECT 
    tom.OrderNumber,
    tom.PartNumber,
    CONCAT(MONTH(tom.DateOrdered), DAY(tom.DateOrdered), YEAR(tom.DateOrdered)) AS DateOrdered, 
    4 AS HardCodedField,
    tom.QtyOrdered,
    tom.LineItemApproved 
  FROM `tblorderlineitem` tom
QUERY;
$select_table=$mysqli->query($query);

Open in new window

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
allenkentAuthor Commented:
Perfect...........
Almost but close enough. My date is now 8122015. I need the 0 in front that 20 removed from the 2015. This gets me there. Thank you.
F IgorDeveloperCommented:
If you want fixed format for dates (eg: 082815 instead of 82815 for 2015-08-28) use DATE_FORMAT function:


SELECT DATE_FORMAT(NOW(),'%m%y%d') 

Open in new window



Format specifiers are defined in https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format : %m (2-digit month) %y (2-digit year) %d (2-digit day)
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
MySQL Server

From novice to tech pro — start learning today.