Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove time from sql

Please can any ove suggest me how i can remove time part from sql dates. I have already read 100s of articles and most of them remove the time but leaves 00:00:00 behine which i don't want also i know that i can remove these ZERO's by doing a convert to varchar but unfortunately i cannot change the type of the date column it has to be date type instead of string

Please advise

Thanks

like image 955
Amit Avatar asked Dec 29 '22 09:12

Amit


2 Answers

A datetime column in the database will always contain both a date portion and a time portion. SQL Server 2008 introduces types that store only date or only time. But, so long as the column is of type datetime, you'll have to accept that the time portion exists, and you can just ignore it in your application (by applying suitable formatting).

You can add a check constraint to the table to ensure that all entries in the column always have the same time portion (e.g. 00:00:00).

like image 82
Damien_The_Unbeliever Avatar answered Jan 10 '23 21:01

Damien_The_Unbeliever


You need to apply a format string to your gridview column to only display the date part. An example of such a string would be dd MMMM yyyy

Is this an ASP.NET gridview? If so there is example code here.

like image 24
Martin Smith Avatar answered Jan 10 '23 23:01

Martin Smith