?
Solved

How to format datetime as mm/dd/yyyy

Posted on 2016-08-03
6
Medium Priority
?
94 Views
Last Modified: 2016-08-03
Need to format data in a view to display as mm/dd/yyyy instead of the default the datetime format of yyyy/mm/dd. Convert?

SELECT        [ZSOFU5080VA07 VBAK-VBELN], [PART NUMBER], [ZSOFU5080VA07 MARA-MFRNR], CAST([SALES ORDER DATE] AS DATETIME) AS [SALES ORDER DATE], DIVISION, 
                         [ZSOFU5080VA07 VBAK-AUART], QUANTITY, [ZSOFU5080VA07 VBAP-POSNR], PLANT, [CUST. PO NUMBER], [STORAGE LOCATION], [REQUESTED DELIVERY DATE], 
                         [PRICE EACH], [PROFIT CENTER], [ZSOFU5080VA07 VBAP-PRCTR], [TOTAL PRICE], [CUSTOMER NUMBER], COUNTRY, [CUSTOMER NAME], [CONTACT INFO], CITY, 
                         [ZIP CODE], STATE, ADDRESS, [ZSOFU5080VA07 MAKT-MATNR], DESCRIPTION, [ZSOFU5080VA07 VBRP-VBELN], [ZSOFU5080VA07 VBRP-POSNR], [QTY INVOICED], 
                         INVOICED, [TOTAL COST], MARGIN, [ZSOFU5080VA07 VBRP-FKLMG], [ZSOFU5080VA07 LIPS-VBELN], [DATE CREATED], [ESTIMATED DELIVERY DATE], 
                         [GOODS ISSUE DATE]
FROM            dbo.ZSOFUVA5SALES_table

Open in new window

0
Comment
Question by:maximus1974
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 66

Expert Comment

by:Jim Horn
ID: 41741119
A buffet of date formats is in Paul Maxwell's article SQL Server Date Styles (formats) using CONVERT()

>Need to format data in a view to display as mm/dd/yyyy instead of ... yyyy/mm/dd
For presentation purposes --> SELECT convert(varchar, GETDATE() ,101)
0
 
LVL 44

Expert Comment

by:zephyr_hex (Megan)
ID: 41741145
DECLARE @test DATE = '2016-08-02'
SELECT CONVERT(VARCHAR(10),@test, 101)

Open in new window


returns:
08/02/2016
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 41741151
(typo fix in my original post, after looking at zephyr_rex's comment)
101 instead of 1, as the 100 means include the first two characters that represent the century.
0
Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

 

Author Comment

by:maximus1974
ID: 41741158
Yes, for presentation purposes, thank you. Using SELECT convert(varchar, GETDATE() ,1) , how does the statement know what field to format?
0
 
LVL 66

Assisted Solution

by:Jim Horn
Jim Horn earned 1000 total points
ID: 41741160
The use of GETDATE() was for illustration only, something you can copy/paste into SSMS, execute, and verify that it works.  Replace the GETDATE() with the column name you wish to use, everywhere you wish to do this, in the SELECT clause of your query.  

There's a wompload of columns in the query you posted, so I didn't want to assume.
0
 
LVL 44

Accepted Solution

by:
zephyr_hex (Megan) earned 1000 total points
ID: 41741171
For example:
SELECT CONVERT(VARCHAR(10),[Sales Order Date], 101)

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question