Link to home
Start Free TrialLog in
Avatar of RIAS
RIASFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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

Cheers
ASKER CERTIFIED SOLUTION
Avatar of Rich Weissler
Rich Weissler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RIAS

ASKER

Thanks Rich,
Will try and brb
Avatar of RIAS

ASKER

Thanks mate, worked like a charm!
I know it has been answered, just posting for completion....

Yes, STYLE code : https://docs.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql#date-and-time-styles

Note that 103 gives you slashes whereas 105 gives you hyphens

And most flexible is the format function : https://docs.microsoft.com/en-us/sql/t-sql/functions/format-transact-sql

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