Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

what's the best way to concatenate this date?

Hi.  I'm looking to get a datetime concatenated value from my table -- this is probably quite easy, but I'm not getting what I want.

this gives me this:  20050320
select convert(varchar(12),getdate(), 112)

what's the right way to return this:  20050320.14:23:53.140

  • 2
1 Solution
Racim BOUDJAKDJIDatabase Architect - Dba - Data ScientistCommented:
This should get you closer to your purpose...
select (convert(varchar(12),getdate(), 112) + '.' + right (cast(getdate() as varchar(50)), len(cast(getdate() as varchar(50)) - 11)  
RLLewisAuthor Commented:
nope - syntactically incorrect.  i added the missing paren after the first getdate(), 112), but now I'm getting this error:
Syntax error converting the varchar value 'Mar 20 2005  2:49PM' to a column of data type int.

select (convert(varchar(12),getdate(), 112)) + '.' + right (cast(getdate() as varchar(50)), len(cast(getdate() as varchar(50)) - 11))

this gets me this:  20050320. 2:48PM
select (convert(varchar(12),getdate(), 112)) + '.' + RIGHT(CONVERT(VARCHAR(30), getdate(), 100), 7)

but I don't want the time in that format.  any ideas?
try this one :

select replace(replace(convert(varchar(23), getdate(), 121),'-',''),' ','.')
RLLewisAuthor Commented:
perfect.  thank you

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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