Hello,
I would like to store begin and end of something as datetime in a table.
Can I create a view that contains begin_date, begin_time, end_date and end_time, derived from the original table?
Thanks
Magnus
Technology Tips and News
Hello,
I would like to store begin and end of something as datetime in a table.
Can I create a view that contains begin_date, begin_time, end_date and end_time, derived from the original table?
Thanks
Magnus
Yes it is possible.
create table mytable (begindate datetime,enddate datetime) insert into mytable values(getdate(), getdate()+12) create view myview as select convert(date, begindate) as begin_date, convert(varchar(8), convert(time, begindate)) as begin_time, convert(date, enddate) as end_date, convert(varchar(8), convert(time, enddate)) as end_time from mytable go drop view myview
Thanks!
I can do a SELECT the way you proposed, but when I try to make a view, I get:
"Cannot call methods on date"
What's wrong?
Magnus
Hello,
I would like to store begin and end of something as datetime in a table.
Can I create a view that contains begin_date, begin_time, end_date and end_time, derived from the original table?
Thanks
Magnus
For instance, you get the string below
select CONVERT(varchar,getdate(),113) go 13 Aug 2009 14:35:05:347
using convert, then you can further use substring to get date and time separately, like
select substring(CONVERT(varchar,getdate(),113),1,12) [Date], substring(CONVERT(varchar,getdate(),113),13,12) [Time] go
It seems like a known issue. Please try as specify in the below link,
http://stackoverflow.com/questions/16180347/sql-server-cannot-call-methods-on-date
Always state what version you are using
create table #t (dt datetime)