Click here to Skip to main content
12,754,175 members (28,044 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
hello

I am using datetime data type for a column and insert the value of a text box in it and i want to insert only date but in the table time also inserted with date

how can i insert only date
Posted 4-Dec-12 6:56am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Convert.ToDateTime(textbox.text).Date
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

try some thing like ...../.
Convert.ToDateTime(Textbox1.Text).Date;
  Permalink  
Comments
Pradeep_kaushik 4-Dec-12 12:14pm
   
DateTime dt = Convert.ToDateTime(TextBox5.Text).Date;

its not working
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

if you don't need the time of the date field why don't you change the column data type as DATE?
then you can insert date in to column by using
Convert.ToDateTime(Textbox1.Text).Date;

If you can't change the data type of the column then you can get DATE from the DATETIME field when you read from the table.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

There are two option for doing this task

1. take varchar datatype of your table
2. take date datatype of your table

when you throw query from css than
string date=DateTime.now.tostring("here your date format like dd/MM/yyyy");

when you retrieving date from your database than

convert(date,your columnname,103)

where 103 is format of date
for more formats view

http://www.sql-server-helper.com/tips/date-formats.aspx[^]
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

Convert your text box value to date only:

string dValue = string.Format("{0:dd-MM-yyyy}",textbox1.Text);

Please also note that SQL Server by default stores time as well if the data type of the column is datetime. If you don't supply time, it will be defaulted to 00:00:00. If you change the column's data type to varchar or smalldatetime.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 6

Hi dear,

string values = dateTimePicker1.Text;
  Permalink  

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

    Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 5 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100