Solved

Date formatting

Posted on 2009-07-15
7
322 Views
Last Modified: 2012-05-07
I have a date field @Date that currently dislays '07/01/2009'.  What statement can I use in my query to format it it like '7/01/2009'?........m/dd/yyyy?

0
Comment
Question by:mattkovo
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 50 total points
ID: 24862882
CONVERT(varchar, datecolumn, 101)
0
 
LVL 7

Expert Comment

by:wrwilson
ID: 24863194
There is no simple T-SQL way to do what you want, the CONVERT will not give you m/dd/yyyy.  
The code below will give you m/d/yyyy.    I have this is a function, because you always seem to need it.  You could edit it to do m/dd/yyyy

CREATE FUNCTION [dbo].[fn_ShortDate]
      (@Date smalldatetime)

RETURNS varchar(12)

AS
BEGIN
DECLARE @String varchar(12)
SET @String = CAST(DATEPART(M,@Date) AS VARCHAR(2)) + '/' + CAST(DATEPART(D,@Date) AS VARCHAR(2)) +
'/' + CAST(DATEPART(YY,@Date) AS CHAR(4))

RETURN(@String)
0
 
LVL 7

Expert Comment

by:wrwilson
ID: 24863202
Oops, need and END at the end of above code
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24865503
>>What statement can I use in my query to format it it like '7/01/2009'?........m/dd/yyyy?<<
This is a presentation not a data problem.  You should be using .NET for that.  

0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24875683
use DATE_FORMAT(date,format)

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format
SET @Date = DATE_FORMAT(@Date,'%c/%d/%Y')

Open in new window

0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24880763
NerdsOfTech,

I am not sure if you noticed, but the author is using MS SQL Server.
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24881467
Oops thanks ac
SET @Date = CONVERT(VARCHAR(10), @DATE, 111) AS [YYYY/MM/DD]

Open in new window

0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 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

16 Experts available now in Live!

Get 1:1 Help Now