Click here to Skip to main content
15,900,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am creating a web application using asp.net.I am using ajaxtoolkit:calenderextender for date type textbox.Can anyone tell me what is the best option to insert date into sql server and retrive data basis on date.
Posted

OP ask:
what is the best option to insert date into sql server and retrive data basis on date


Best option use DateTime[^] datatype.

Always use appropriate datatype to store data in order to perform queries effectively
 
Share this answer
 
v3
Use the Datatype as Datetime in your table

XML
<asp:CalendarExtender ID="CalendarExtender1" TargetControlID="txtfrom" runat="server" Format="dd/MM/yyyy">
               </asp:CalendarExtender>
 
Share this answer
 
Comments
Sandip Paul 491984 3-Mar-14 8:21am    
is the calender extender date format is dependent on windows date format?
Tom Marvolo Riddle 3-Mar-14 8:23am    
It depends on system format in local and server datetime format after hosting
Sandip Paul 491984 3-Mar-14 8:27am    
means the computer in which the aspx has been uploaded
Tom Marvolo Riddle 3-Mar-14 8:29am    
yup you're right.
Send date as string like "2014-03-03"(yyyy-MM-dd) to sp

Sp sample
Create procedure sample
@date varchar(20)
as
begin
// done
end

Aspx
XML
<asp:CalendarExtender ID="CalendarExtender1" TargetControlID="txtfrom" runat="server" Format="yyyy-MM-dd">
               </asp:CalendarExtender>


you can use any format but finally you have to convert to this 'yyyy-MM-dd' format.
 
Share this answer
 
v2
First see this tutorial[^] on Ajax Calendar Control.

And then whatever you're saying is this,
XML
<asp:TextBox ID="txtYouDateTime" runat="server" Width="190px" ></asp:TextBox>

<asp:ImageButton runat="Server" ID="ImgCal1" ImageUrl="calendar.png" AlternateText="Click to show calendar" OnClientClick="return false;"  />

<ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server"
                    TargetControlID="txtYouDateTime" PopupButtonID="ImgCal1" Format="dd/MMM/yyyy hh:mm" />

String dt = DateTime.Parse(txtYouDateTime.Text).ToString("yyyyMMdd HH:mm:ss")

Now fire the Insert query using dt variable within it.
-KR
 
Share this answer
 
INSERT INTO MyTable (MyDate) Values (Convert(DateTime,'"+txtboxname+"',112))
 
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