Avatar of Alex A
Alex A
 asked on

SQL Server: DateTime column in select

SQL Server DateTime column


how to display only date part in select? 

and how to display empty value  instead of NULL, and also not 1900-01-01 ?

SQLMicrosoft SQL Server

Avatar of undefined
Last Comment
arnold

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
ste5an

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Peter Chan

Hi,
Try the following, to convert it to Varchar. The following does also convert it to the current date time if it is null.
convert(varchar, isnull(date_column,getdate()), 103)



Open in new window

arnold

usually, if the column is defined as datetime(), you would use the 1-1-1901 as the default value mining NULL/EMPTY.

you can use the datediff to assess or use that info in your query.

it is common that vendor use the 1-1-1901 as a null date or they use a date that is more than a 100 years from the software design depending on what the date is for, i.e. you might se 1-1-1901 currently it accounts for people whose age is approaching 120.
arnold

One option is to use case and substring (column_name,0,10)
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck