Solved

Format date as MMDDYYYY

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
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
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

708 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

19 Experts available now in Live!

Get 1:1 Help Now