How to insert date into table

Posted by Karthikreddy under Sql Server on 3/28/2013 | Points: 10 | Views : 6298 | Status : [Member] | Replies : 8
hi (find the attachments)

i want to insert only date into table not date and time i used date data type in table but while retrieving values from database it showing date with default time 12:00 AM
how can i display only time as it in db table

k@rth!k
karthikreddy08a50@gmail.com



Responses

Posted by: Pandians on: 3/28/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
You can use DATE data type instead of DATETIME! If you are using SQL Server 2008 and above!
CREATE TABLE DateTable

(
Column1 DATE
)

INSERT DateTable VALUES(GETDATE())
GO

SELECT * FROM DateTable
GO
If you are using SQL Server 2005 and below then you can use DATETIME data type and use CONVERT function while retrieve the data
CREATE TABLE DateTable

(
Column1 DATETIME
)

INSERT DateTable VALUES(GETDATE())
GO

SELECT CONVERT(VARCHAR(10),Column1, 21) FROM DateTable
GO


Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Karthikreddy, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: aswinialuri-19361 on: 3/28/2013 [Member] Starter | Points: 25

Up
0
Down
Hi

Try this if you use date as datatype means you it will dispaly both date and time
if you want to display only date means then you will use
LongDate
Example: Saturday, March 28, 2013.
short Date:
Ex:3/28/2013
if you need only time means then you same as settings on the time tab

Thank You

Mark as Answer if it helps you
Thanks&Regards
Aswini Aluri

Karthikreddy, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikreddy on: 3/28/2013 [Member] Starter | Points: 25

Up
0
Down
error
Column, parameter, or variable #10: Cannot find data type LongDate.


k@rth!k
karthikreddy08a50@gmail.com

Karthikreddy, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikreddy on: 3/28/2013 [Member] Starter | Points: 25

Up
0
Down
hi Pandians

i am inserting date from asp page using ajax calender extender
it storing in table like 2013-03-06 format only while displaying on the web page it showing like 3/6/2013 12:00:00 AM
there i don't want time i want only date

k@rth!k
karthikreddy08a50@gmail.com

Karthikreddy, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 3/28/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

try this code

DataSet ds=new DataSet ();
SqlDataAdapter sqlmd = new SqlDataAdapter("Select * from Table_2", con);
sqlmd.Fill(ds);
string StDate = "";
string STime = "";
string Speriod = "";
string test1 = ds.Tables[0].DefaultView[0][1].ToString();
StDate = test1.Split(' ')[0];
STime = test1.Split(' ')[1];
Speriod = test1.Split(' ')[2];
Response.Write(" Date : " + StDate + " Time : " + STime + " " +Speriod);

Mark as Answer if its helpful to you

Karthikreddy, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sriramnandha on: 5/12/2013 [Member] Starter | Points: 25

Up
0
Down
protected void Btn_Submit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(contour);
DateTime startdate = Convert.ToDateTime(TextBox_startdate.Text);
string inserttour = "insert into tourprogram(startdate,fromplace,toplace)values('" + startdate + "','" + TextBox_fromplace.Text + "','" + TextBox_toplace.Text + "')";

con.Open();
SqlCommand cmd = new SqlCommand(inserttour, con);
cmd.ExecuteNonQuery();
con.Close();
showgrid();

}

sriram

Karthikreddy, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 5/13/2013 [Member] Starter | Points: 25

Up
0
Down
use convert(varchar,'"@date", 103)

Karthikreddy, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Neeraaj.Sharma on: 6/27/2013 [Member] Starter | Points: 25

Up
0
Down
please visit the link:

http://www.tutorialsqlserver.com/Insert/Insert-in-Sql-Server.htm

Karthikreddy, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response