Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 t-sql 2012 change date value

Author  Topic 

jassie
Constraint Violating Yak Guru

332 Posts

Posted - 2015-03-31 : 12:10:48
In t-sql 2012, I have one column called Userdate and is in a datetime format. I need to join this date column to another table by date where the column in the other table is called ABSDT varchar(34). The value of the data in the column called ABSDT looks like:
'20140331'. Basically the format of the column is yyyymmdd.

Thus can you show me how to change the format of the column called Userdate to be in the format of yyyymmdd so that I can compare the value of the 2 columns with each other?

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-03-31 : 13:23:07
replace(convert(char(10), Userdate,102),'.','')
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2015-04-01 : 08:59:05

WHERE datetime_col=CAST(string_col as DATETIME)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jassie
Constraint Violating Yak Guru

332 Posts

Posted - 2015-04-01 : 10:04:47
Thanks this works fine!
Go to Top of Page
   

- Advertisement -