Solved

datetime to 01 december 1990

Posted on 2006-07-13
15
330 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
ID: 17098672
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
ID: 17098682
you can easily convert to    DD-MMM-YYYY format using

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

Author Comment

by:DaFou
ID: 17098684
wicked, can i also set the language? i want to be able to set it in dutch
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 17098827
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
ID: 17099065
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
ID: 17099505
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
ID: 17099759
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
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 17099780
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
ID: 17101863
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
ID: 17106318
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
ID: 17106320
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
ID: 17106328
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
ID: 17106352
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
ID: 17108417
Interesting use of CROSS JOIN.
0
 
LVL 2

Author Comment

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

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

808 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