Solved

Format date as MMDDYYYY

Posted on 2011-09-29
5
311 Views
Last Modified: 2012-05-12
I need to always return the date as 8 characters

so 8/27/2011

would be

09272011
0
Comment
Question by:lrbrister
  • 3
5 Comments
 
LVL 33

Accepted Solution

by:
knightEknight earned 500 total points
ID: 36818042
select CONVERT(varchar(8),getdate(),112)  -- yyyymmdd

for your requirements:

select right(CONVERT(varchar(8),getdate(),112),4) + LEFT(CONVERT(varchar(8),getdate(),112),4)

0
 
LVL 33

Assisted Solution

by:knightEknight
knightEknight earned 500 total points
ID: 36818043
but replace getdate() with your date column name
0
 
LVL 3

Expert Comment

by:kinsey
ID: 36818047
select convert(varchar, datecolumnname,112) gives YYYYMMDD
so

select right(convert(varchar,getdate(),112),4)+left(convert(varchar,getdate(),112),4)

give MMDDYYY
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 36818057
another option:

select REPLACE( CONVERT(varchar(10),getdate(),101), '/', '' )
0
 

Author Closing Comment

by:lrbrister
ID: 36818094
Thanks
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
need help in sql 4 66
SQL Server Deadlocks 12 50
Help Extract Specific in SQL 8 24
MSSQL: Substring and Charindex error 7 18
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
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.

920 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

11 Experts available now in Live!

Get 1:1 Help Now