• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

convert date to format ddmmyyyy

hi experts
i need convert datat type date to dd.mm.yyyy

CREATE TABLE [dbo].[days](
      [PKDate] [date] NOT NULL,
      [calendar_year] [smallint] NULL,


select PKDate
from days dy
where dy.calendar_year = '2015'

2015-01-01
2015-01-02
2015-01-03
2015-01-04
2015-01-05
0
enrique_aeo
Asked:
enrique_aeo
  • 2
1 Solution
 
Shaun KlineLead Software EngineerCommented:
Use the CONVERT function along with the REPLACE function:
REPLACE(CONVERT(varchar(10), PKDate, 103), '/', '')

MSDN Convert Page lists other formats for the convert function.
0
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
Enrique you need to be more clear with your questions and examples.
For example, you defined calendar_year as smallint but in WHERE clause you're using a string ("where dy.calendar_year = '2015'").

And what's this? Is the current result or what you're expecting?
2015-01-01
2015-01-02
2015-01-03
2015-01-04
2015-01-05

If is what you're expecting, what are the current results?
If is the current results, what are you expecting as output?
0
 
enrique_aeoAuthor Commented:
select '2015', dy.calendar_week_in_year, min(REPLACE(CONVERT(varchar(10), PKDate, 103), '/', '.'))
from days dy
where dy.calendar_year = '2015'
group by dy.calendar_week_in_year
0
 
enrique_aeoAuthor Commented:
2015      1      01.01.2015
2015      2      04.01.2015
2015      3      11.01.2015
2015      4      18.01.2015
2015      5      25.01.2015
2015      6      01.02.2015
2015      7      08.02.2015
2015      8      15.02.2015
2015      9      22.02.2015
2015      10      01.03.2015
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now