I have a form that has the controls [datetextbox] and [weekendingtextbox]. I need to be able to be sure that the user enters the correct year in both. So if the year in [weekendingtextbox] is 2011 then the year in [datetextbox] needs to be 2011. How would
I go about doing this when the format for each box is mm/dd/yyyy.
You can convert the Textbox value to DateTime format using DateTime.Parse() method. And you can use Year property of DateTime class to get the Year information.
You can use asp:CustomValidator and implement your logic there. As the above user said, you can first parse the strings you are getting from the textboxes into valid DateTime objects so you can performs datetime operations on that object. Once you've converted
those to DateTime objects, you can use 'Year' property to get the year of the date. Hope it helps you to implement your logic.
Leesha
Member
47 Points
94 Posts
question re year comparison in a mm/dd/yyyy format
Feb 20, 2012 01:11 AM|LINK
Hi,
I have a form that has the controls [datetextbox] and [weekendingtextbox]. I need to be able to be sure that the user enters the correct year in both. So if the year in [weekendingtextbox] is 2011 then the year in [datetextbox] needs to be 2011. How would I go about doing this when the format for each box is mm/dd/yyyy.
Thanks,
Leesha
vsdev
Contributor
2230 Points
453 Posts
Re: question re year comparison in a mm/dd/yyyy format
Feb 20, 2012 01:51 AM|LINK
You can convert the Textbox value to DateTime format using DateTime.Parse() method. And you can use Year property of DateTime class to get the Year information.
Blog: dotnetthoughts
Download Capture It Plus
Ruchira
All-Star
42888 Points
7020 Posts
MVP
Re: question re year comparison in a mm/dd/yyyy format
Feb 20, 2012 06:01 AM|LINK
Hi,
You can use asp:CustomValidator and implement your logic there. As the above user said, you can first parse the strings you are getting from the textboxes into valid DateTime objects so you can performs datetime operations on that object. Once you've converted those to DateTime objects, you can use 'Year' property to get the year of the date. Hope it helps you to implement your logic.
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.vinay13mar
Star
7756 Points
1626 Posts
Re: question re year comparison in a mm/dd/yyyy format
Feb 20, 2012 06:07 AM|LINK
Convert the date into specific format and then compare.
plz check the links for formating the date
http://forums.asp.net/t/1313908.aspx/1
V.K.Singh
Leesha
Member
47 Points
94 Posts
Re: question re year comparison in a mm/dd/yyyy format
Feb 21, 2012 11:48 AM|LINK
Hi, it is already in the correct date format. The problem occurs is someone puts in the wrong year.
Leesha
vinay13mar
Star
7756 Points
1626 Posts
Re: question re year comparison in a mm/dd/yyyy format
Feb 21, 2012 11:57 AM|LINK
Hi,
What do you meen by wrong year
V.K.Singh
srinanthuram
Contributor
6800 Points
1549 Posts
Re: question re year comparison in a mm/dd/yyyy format
Feb 21, 2012 01:38 PM|LINK
hi
http://forums.asp.net/t/1410702.aspx/1
or
use asp:CompareValidator
<asp:CompareValidator Type=Date Operator=DataTypeCheck [other properties] />
For more on this and solutions to other common validation questions, check out my article: http://aspalliance.com/699.
thank u