I am converting some Oracle views to TSQL. In Oracle, there are dates in a view that are formatted like:
TO_DATE (TO_CHAR (sysdate, 'mm/dd/yyyy'), 'mm/dd/yyyy') as SDATE'
When you look at the DDL for this view, the SDATE column has a data type of DATE
Is there a way to format a date column in a view in TSQL, that returns as a date? I'm finding the only way to format a date in SQL Server is to convert it into VARCHAR. I tried in the view:
format(CONVERT(DateTime, getdate(), 101),'MM/dd/yyyy') SDATE
which returns as nvarchar(4000) and if I convert it back to a date, it loses it formatting. The problem arises with the calling program erroring while calling the view, because it is expecting a date datatype.
Thanks,
Paul