Skip to content
Advertisement

Trying to convert SQL getdate into varchar with no in-between characters

I have a list of auto-generated tables in MS-SQLServer that differ only in the date listed at the end of the name. The challenge is that I want to create a script that always references a table ‘x days back’.

So for example if the table name would be: dbo.tablename_20200825

I can get “close” to the date format I need as a string with the following statement and style

select convert(varchar(10), getdate(), 102);

enter image description here

However I still have those periods of separation between each part of the date.

How do I make the resulting string appear as ‘20200825’ instead of ‘2020.08.25’

Thank you as always for any insight and help.

Advertisement

Answer

I think you’re looking for 112

select convert(varchar(10), getdate(), 112);

Results

20200825
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement