November 1, 2013 at 2:56 pm
Hi,
I am trying to change the date format from "2012-06-02 12:25:32.393" to "2012-06"
SELECT Mydate, CONVERT(VARCHAR(7),MyDate, 120) As NewDate
FROM MyData
This works, but NewDate is not in Date Format. I just want Year-Month
November 1, 2013 at 3:21 pm
TJT (11/1/2013)
Hi,I am trying to change the date format from "2012-06-02 12:25:32.393" to "2012-06"
SELECT Mydate, CONVERT(VARCHAR(7),MyDate, 120) As NewDate
FROM MyData
This works, but NewDate is not in Date Format. I just want Year-Month
It is a zillion times better if you can do this formatting in the front end instead of in sql. To get that type of format in sql you will have to get the individual dateparts.
What you have should however return your date in the format you want.
select CONVERT(VARCHAR(7),GETDATE(), 120)
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply