Solved

Format date as MMDDYYYY

Posted on 2011-09-29
5
345 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
[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
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
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.

688 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