user3197575
user3197575

Reputation: 277

how do I convert a date int to datetime ( Getdate() ) in sql server?

how do I convert or cast a date in integer like yyymmdd to a datetime format so that and picks today's date , getdate() ?

I have tried these:

cast(DateIDas ,getdate()) cast(DateID,as datetime,getdate()

Upvotes: 0

Views: 1217

Answers (1)

rinuthomaz
rinuthomaz

Reputation: 1413

Try this...

SELECT CONVERT(VARCHAR(10), getdate(), 112)

with variable

DECLARE @myDate DATE= '10/15/2014'
SELECT CONVERT(VARCHAR(10), @myDate, 112)

convert date(int) into datetime

DECLARE @myIntDate int= 20141015;
select MyDate = cast(cast(@myIntDate as char(8)) as datetime);

Upvotes: 1

Related Questions