user2871190
user2871190

Reputation: 251

SQL - Getting date with one digit for day and month

I need a date in the following format: 1.1.2018 So no leading 0 if not needed. I checked the date formats and it doesn't exist this way.

My way would be to build a stored proc or function, converting the date to a varchar and deleting the 0 if needed.

Is there a better solution where I can already get that result without building a stored proc / function?

Any help is greatly appreciated!

Upvotes: 0

Views: 2261

Answers (1)

Javlon Ismatov
Javlon Ismatov

Reputation: 194

--if you are using MSSQL Server 
select getdate() 'getdate', (cast(month(getdate()) as varchar)+'.'+cast(day(getdate()) as varchar)+'.'+ cast(year(getdate()) as varchar)) 'getdate_new_format'

Upvotes: 1

Related Questions