Avatar of maximus1974
maximus1974

asked on 

How to format datetime as mm/dd/yyyy

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

Microsoft SQL ServerMicrosoft SQL Server 2005Microsoft SQL Server 2008SQL

Avatar of undefined
Last Comment
zephyr_hex (Megan)
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

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)
DECLARE @test DATE = '2016-08-02'
SELECT CONVERT(VARCHAR(10),@test, 101)

Open in new window


returns:
08/02/2016
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

(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.
Avatar of maximus1974
maximus1974

ASKER

Yes, for presentation purposes, thank you. Using SELECT convert(varchar, GETDATE() ,1) , how does the statement know what field to format?
SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
ASKER CERTIFIED SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo