Click here to Skip to main content
Rate this: bad
good
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 5: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 at 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
0 OriginalGriff 225
1 Richard MacCutchan 100
2 kbrandwijk 90
3 ChauhanAjay 80
4 ProgramFOX 80
0 Sergey Alexandrovich Kryukov 9,050
1 OriginalGriff 8,151
2 CPallini 2,613
3 Richard MacCutchan 2,221
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 5 Dec 2012
Copyright © CodeProject, 1999-2014
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