Click here to Skip to main content
15,894,540 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am trying to enter date into database where my column type is Date. But the value is like this 1/15/2011 12:00:00 AM whereas I just want to enter 1/15/2011. Please guide how can I do that?

thanks
Posted

Hi ,

Insert into yourtable(columnname) values(convert(varchar(10),yourdate,120)).

Hope this helps...
 
Share this answer
 
Hi,

Try this line

C#
string shdate=DateTime.Now.ToShortDateString();


otherwise retrieve date values from database and then cut into whatever format you want.
 
Share this answer
 
You can't - a Date always contains the time since an agreed moment in time, it isn't a date in the sense of 2011-09-16, it is a interval in the sense of xxx milliseconds since midnight on "such-and-such" a date, Universal Coordinated Time.

Don't worry about it - you can mask out the hour:min:sec part when you format it for a display as needed.
 
Share this answer
 
you may use like this

update tblTable set Datecolumn=left(getdate(),10)
or
update tblTable set Datecolumn=left(datecolumn,10)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900