?
Solved

Format date as MMDDYYYY

Posted on 2011-09-29
5
Medium Priority
?
349 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 2000 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 2000 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

649 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