Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 16, 2012 07:42 AM by mm10
Contributor
2070 Points
531 Posts
Apr 16, 2012 07:13 AM|LINK
Hi,
Try for this
http://www.sql-server-helper.com/tips/date-formats.aspx
3230 Points
668 Posts
Example of range validator
Here is your textbox control and rangevalidator control
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
<asp:RangeValidator ID="RangeValidator1" runat="server"> </asp:RangeValidator>
In code behind
RangeValidator1.ControlToValidate = "TextBox1";
RangeValidator1.Type = ValidationDataType.Date;
RangeValidator1.MinimumValue = DateTime.Now.ToShortDateString();
RangeValidator1.MaximumValue = DateTime.Now.AddDays(7).ToShortDateString();
RangeValidator1.ErrorMessage = "Select date between today to next 7 day!";
Member
31 Points
51 Posts
Apr 16, 2012 07:16 AM|LINK
Yes but this showing error as string is not a valid datetime
559 Points
164 Posts
Apr 16, 2012 07:20 AM|LINK
Let the date save in mm/dd format, if you want to display in dd/mm format, then while fetching the data, in the query, use to_char.
select to_char(theDateColumnName,'DD/MM/YYYY') Displayed_date from table1;
P.S. - It has to be to_char only to maintain the format.
Apr 16, 2012 07:23 AM|LINK
Please paste the string for which you are getting error
6395 Points
1182 Posts
Apr 16, 2012 07:42 AM|LINK
jesunathan Yes but this showing error as string is not a valid datetime
If TextBox1.Text = "21-2-2012" the following works, so what is the value of TextBox1.Text when you get the error?
string DateString = TextBox1.Text; // = "21-2-2012" DateTime date = DateTime.ParseExact(DateString, "dd-M-yyyy", null);
kirupa.v
Contributor
2070 Points
531 Posts
Re: how to get dd/mm/yyyy and stores as mm/dd/yyyy in asp.net
Apr 16, 2012 07:13 AM|LINK
Hi,
Try for this
http://www.sql-server-helper.com/tips/date-formats.aspx
tusharrs
Contributor
3230 Points
668 Posts
Re: how to get dd/mm/yyyy and stores as mm/dd/yyyy in asp.net
Apr 16, 2012 07:13 AM|LINK
Hi,
Example of range validator
Here is your textbox control and rangevalidator control
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
<asp:RangeValidator ID="RangeValidator1" runat="server"> </asp:RangeValidator>
In code behind
RangeValidator1.ControlToValidate = "TextBox1";
RangeValidator1.Type = ValidationDataType.Date;
RangeValidator1.MinimumValue = DateTime.Now.ToShortDateString();
RangeValidator1.MaximumValue = DateTime.Now.AddDays(7).ToShortDateString();
RangeValidator1.ErrorMessage = "Select date between today to next 7 day!";
( Mark as Answer if it helps you out )
View my Blog
jesunathan
Member
31 Points
51 Posts
Re: how to get dd/mm/yyyy and stores as mm/dd/yyyy in asp.net
Apr 16, 2012 07:16 AM|LINK
Yes but this showing error as string is not a valid datetime
sargamlucy
Member
559 Points
164 Posts
Re: how to get dd/mm/yyyy and stores as mm/dd/yyyy in asp.net
Apr 16, 2012 07:20 AM|LINK
Let the date save in mm/dd format, if you want to display in dd/mm format, then while fetching the data, in the query, use to_char.
select to_char(theDateColumnName,'DD/MM/YYYY') Displayed_date from table1;
P.S. - It has to be to_char only to maintain the format.
Regards,
Snigdha
Please Mark as Answer if my reply helped you.
tusharrs
Contributor
3230 Points
668 Posts
Re: how to get dd/mm/yyyy and stores as mm/dd/yyyy in asp.net
Apr 16, 2012 07:23 AM|LINK
Hi,
Please paste the string for which you are getting error
( Mark as Answer if it helps you out )
View my Blog
mm10
Contributor
6395 Points
1182 Posts
Re: how to get dd/mm/yyyy and stores as mm/dd/yyyy in asp.net
Apr 16, 2012 07:42 AM|LINK
If TextBox1.Text = "21-2-2012" the following works, so what is the value of TextBox1.Text when you get the error?
string DateString = TextBox1.Text; // = "21-2-2012"
DateTime date = DateTime.ParseExact(DateString, "dd-M-yyyy", null);