Solved

datetime to 01 december 1990

Posted on 2006-07-13
15
323 Views
Last Modified: 2008-02-26
Hi All,

Is there a way to convert a datetime field to a string with format 11 decemeber 1990 in a select statment?
0
Comment
Question by:DaFou
  • 5
  • 4
  • 3
  • +1
15 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
Comment Utility
SELECT CAST(DAY(urDatetimeColumn)as varchar)+'-'+DATENAME (mm,urDatetimeColumn)+'-'+CAST(Year(urDatetimeColumn) as varchar)
0
 
LVL 75

Assisted Solution

by:Aneesh Retnakaran
Aneesh Retnakaran earned 100 total points
Comment Utility
you can easily convert to    DD-MMM-YYYY format using

SELECT CONVERT(varchar(11),GETDATE(),113)
0
 
LVL 2

Author Comment

by:DaFou
Comment Utility
wicked, can i also set the language? i want to be able to set it in dutch
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
Comment Utility
DaFou,

I am not aware of any method yet... you can handle this at the front end

Aneesh
0
 
LVL 50

Expert Comment

by:Lowfatspread
Comment Utility
like this

select stuff(left(convert(varchar(30),TheDate,113),len(convert(varchar(30),TheDate,113))-13) , 4,3,datename(m,Thedate))
 from (select getdate() as Thedate
          union select '20061201' union select '20061231 01:01:01.000') as x
 
0
 
LVL 2

Author Comment

by:DaFou
Comment Utility
Lowfatspread,

using your suggestion renders english month names. how can i get Dutch month names?
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 200 total points
Comment Utility
Select      CAST(Day(YourColumnName) As varchar(2)) +
      CASE
            WHEN MONTH(YourColumnName) = 1 THEN ' Januari '
            WHEN MONTH(YourColumnName) = 2 THEN ' Februari '
            WHEN MONTH(YourColumnName) = 3 THEN ' Maart '
            WHEN MONTH(YourColumnName) = 3 THEN ' April '
...

      END +
      CAST(Year(YourColumnName) As varchar(4))
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
Typo, this:
 WHEN MONTH(YourColumnName) = 3 THEN ' April '

Should have been:
 WHEN MONTH(YourColumnName) = 4 THEN ' April '

I will leave the rest of the months as an exercise for you.
0
 
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 200 total points
Comment Utility
This might be a tad simpler:
Declare @MonthNames varchar(120)
Set @MonthNames = 'januari  februari maart    april    mei      juni     juli     augustus septemberoktober  november december'
Select      CAST(Day(YourColumnName) As varchar(2)) + ' ' +
      RTRIM(SUBSTRING(@MonthNames, (MONTH(YourColumnName) - 1) * 9 + 1, 9)) + ' ' +
      CAST(Year(YourColumnName) As varchar(4))

Or if you prefer it all in statement:
Select      CAST(Day(YourColumnName) As varchar(2)) + ' ' +
      RTRIM(SUBSTRING('januari  februari maart    april    mei      juni     juli     augustus septemberoktober  november december', (MONTH(YourColumnName) - 1) * 9 + 1, 9)) + ' ' +
      CAST(Year(YourColumnName) As varchar(4))
0
 
LVL 50

Expert Comment

by:Lowfatspread
Comment Utility
borrowing from acperkins...

select stuff(left(convert(varchar(30),TheDate,113),len(convert(varchar(30),TheDate,113))-13) , 4,3,rtrim(substring(Mname,(Month(thedate)-1)*9 +1,9))
 from (select getdate() as Thedate
          union select '20061201' union select '20061231 01:01:01.000') as x
cross join (select 'januari  februari maart    april    mei      juni     juli     augustus septemberoktober  november december' as Mname) as y
     
0
 
LVL 50

Expert Comment

by:Lowfatspread
Comment Utility
sorry

select stuff(left(convert(varchar(30),TheDate,113),len(convert(varchar(30),TheDate,113))-13) , 4,3,rtrim(substring(Mname,(Month(thedate)-1)*9 +1,9)))
 from (select getdate() as Thedate
          union select '20061201' union select '20061231 01:01:01.000') as x
cross join (select 'januari  februari maart    april    mei      juni     juli     augustus septemberoktober  november december' as Mname) as y
0
 
LVL 50

Expert Comment

by:Lowfatspread
Comment Utility
sorry

select stuff(left(convert(varchar(30),TheDate,113),len(convert(varchar(30),TheDate,113))-13) , 4,3,rtrim(substring(Mname,(Month(thedate)-1)*9 +1,9)))
 from (select getdate() as Thedate
          union select '20061201' union select '20061231 01:01:01.000') as x
cross join (select 'januari  februari maart    april    mei      juni     juli     augustus septemberoktober  november december' as Mname) as y
0
 
LVL 50

Assisted Solution

by:Lowfatspread
Lowfatspread earned 200 total points
Comment Utility
actually we don't need the left expression at all.. so its

select stuff(convert(char(11),TheDate,113) , 4,3,rtrim(substring(Mname,(Month(thedate)-1)*9 +1,9)))
 from (select getdate() as Thedate
          union select '20061201' union select '20061231 01:01:01.000') as x
cross join (select 'januari  februari maart    april    mei      juni     juli     augustus septemberoktober  november december' as Mname) as y


convert date to DD mmm YYYY
then replace the 3 character month name (starting at byte 4) with its full length Dutch equivalent...

0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
Interesting use of CROSS JOIN.
0
 
LVL 2

Author Comment

by:DaFou
Comment Utility
wow guys, thx alot. give me a few to decide how to devide the points
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

762 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

10 Experts available now in Live!

Get 1:1 Help Now