Date format

Change format f the date

create table #table1 (coldate date)
insert #table1 values ('19000101'),('19000202'),(getdate())

declare @sql varchar(2000)

set @sql = 'select iif(coldate < ''19000102'','''',convert(char(10), coldate, 101)) coldate from #table1'

exec (@sql)

Open in new window

This  gives me an American format date is it possible to have date like DD-MM-YYYY

Who is Participating?
Rich WeisslerProfessional Troublemaker^h^h^h^h^hshooterCommented:
RIASAuthor Commented:
Thanks Rich,
Will try and brb
RIASAuthor Commented:
Thanks mate, worked like a charm!
Mark WillsTopic AdvisorCommented:
I know it has been answered, just posting for completion....

Yes, STYLE code :

Note that 103 gives you slashes whereas 105 gives you hyphens

And most flexible is the format function :

Heres an example
declare @coldate date = getdate()

select format(@coldate,'dd-MM-yyyy')

select format(@coldate,'d','en-gb')

select convert(char(10), @coldate, 105)

select convert(char(10), @coldate, 103)

Open in new window

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.

All Courses

From novice to tech pro — start learning today.