Solved

SQL date formatting

Posted on 2013-06-18
6
247 Views
Last Modified: 2013-06-18
Hello all,
I have a date time column DispensedDate which has values like :2012-06-07 00:00:00.000.
How to convert this to MM/DD/YY in a query
0
Comment
Question by:Star79
6 Comments
 
LVL 11

Accepted Solution

by:
Guru Ji earned 250 total points
ID: 39257510
SELECT convert(varchar, getdate(), 101) – mm/dd/yyyy - 10/02/2008
0
 
LVL 11

Expert Comment

by:Guru Ji
ID: 39257513
replace getdate() with your date column
0
 
LVL 2

Expert Comment

by:Averitteg
ID: 39257516
Try:
SELECT CAST(table.DispensedDate AS DATE) AS DispensedDate
0
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 

Author Comment

by:Star79
ID: 39257524
hello all,
I need it like
MM/DD/YY
Note the year its only YY
0
 
LVL 15

Assisted Solution

by:tim_cs
tim_cs earned 250 total points
ID: 39257582
Replace his 101 with just 1.
0
 
LVL 2

Expert Comment

by:Averitteg
ID: 39257618
Select CONVERT(VARCHAR(11),DispensedDate,1) as Dispensed Date from table

Tim_cs was correct: this version works just fine in a sql query. Tested success in Sql 2008.
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now