Link to home
Start Free TrialLog in
Avatar of RLLewis
RLLewis

asked on

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

Avatar of Racim BOUDJAKDJI
Racim BOUDJAKDJI
Flag of Algeria image

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)  
Avatar of RLLewis
RLLewis

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of BillAn1
BillAn1

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 RLLewis

ASKER

perfect.  thank you