Question

I am pretty new to SQL and hope someone here can help me with the following:

I have a table in SQL Server with one column storing dates and I have a simple stored procedure to select data from this table.

Currently it fetches the date including hours and minutes. How can I achieve that it fetches the date in format yyyy-mm-dd (without the hours and minutes) ? My column is called "logDate" and my table is called "logTable".

Thanks for any help with this, Tim

Was it helpful?

Solution

If you only want to store the date, convert the column to a date type, not a datetime.

If you want to keep the date and time in the data, but just display the date

 select convert(date, logDate) from logTable

If you want to return the date as a string, use convert

select convert(varchar(10), logDate, 120) from logTable
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top