x

How Do I Convert A Datetime Datatype Into YYYYMM Char Format?

At the moment I have:

select convert(varchar(10),getdate(),101);

Which produces 11/19/2009, however I need it to read 200911 i.e. (YYYYMM)

TIA

more ▼

asked Nov 19, 2009 at 11:01 AM in Default

avatar image

David 2 1
732 54 58 65

(comments are locked)
10|1200 characters needed characters left

2 answers: sort voted first

Here's one way:

select convert(char(6), getdate(), 112)            
more ▼

answered Nov 19, 2009 at 12:23 PM

avatar image

TG
1.8k 3 5

(comments are locked)
10|1200 characters needed characters left

My advice would be to format the date in your application, not in SQL Serer. If you format the date in SQL Server it will be sent as a text string to the application, rather than as a date/time datatype, and thus the applicaiton can do other useful things with it in its native format.

more ▼

answered Nov 19, 2009 at 02:39 PM

avatar image

Kristen ♦
2.2k 7 11 14

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x501
x80

asked: Nov 19, 2009 at 11:01 AM

Seen: 18207 times

Last Updated: Nov 19, 2009 at 11:01 AM

Copyright 2016 Redgate Software. Privacy Policy