?
Solved

Asp/Net Validation date Issue

Posted on 2016-11-01
9
Medium Priority
?
104 Views
Last Modified: 2016-11-03
I have a sub that checks the minimum value of a textbox

Public Sub ValidCheck()

        rvCompDateCheck.MinimumValue = DateTime.Today.AddDays(-7).ToShortDateString()
        rvCompDateCheck.MaximumValue = DateTime.Today.ToShortDateString()


    End Sub

Open in new window



It worked until yesterday(31/10/2016)

Now today (01/11/2016)  

I get the below error

The MaximumValue 01/11/2016 cannot be less than the MinimumValue 25/10/2016 of rvCompDateCheck.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: The MaximumValue 01/11/2016 cannot be less than the MinimumValue 25/10/2016 of rvCompDateCheck.

Open in new window


I know its something to do with it reading the date as a string but can't find the right solution... help.  Thanks
0
Comment
Question by:Ed
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 

Author Comment

by:Ed
ID: 41868150
I've tried this but still get the same error

 
  Public Sub ValidCheck()

        System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-GB", True)
        System.Threading.Thread.CurrentThread.CurrentUICulture = New System.Globalization.CultureInfo("en-GB", True)


        Dim Minval As Date
        Dim Maxval As Date

        Minval = DateTime.Today.AddDays(-7)

        Maxval = DateTime.Today


        rvCompDateCheck.MinimumValue = Minval
        rvCompDateCheck.MaximumValue = Maxval




    End Sub

Open in new window

0
 
LVL 29

Expert Comment

by:Pawan Kumar
ID: 41868160
Try..

Dim x As DateTime = DateTime.Now
rvCompDateCheck.MaximumValue = x.ToShortDateString()

x = now.AddDays(-7)
rvCompDateCheck.MinimumValue = x.ToShortDateString()
0
 
LVL 29

Expert Comment

by:Pawan Kumar
ID: 41868167
Looks like a format issue, try below if above is not working..

DateTime.Today.ToString("yyyyMMdd")

Public Sub ValidCheck()

        rvCompDateCheck.MinimumValue = DateTime.Today.AddDays(-7).ToString("yyyyMMdd")
        rvCompDateCheck.MaximumValue = DateTime.Today.ToString("yyyyMMdd")

End Sub
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Ed
ID: 41868309
Thanks

the above works...almost.

No error anymore but it is not picking up on the fact that

31/10/2016  is less than 01/11/2016

It needs to be UK format I think.
0
 
LVL 29

Expert Comment

by:Pawan Kumar
ID: 41868341
Hi edjones1,

Glad that it helped !!

Regards,
Pawan
0
 

Author Comment

by:Ed
ID: 41868353
any ideas on how to read it in uk format?
0
 
LVL 29

Accepted Solution

by:
Pawan Kumar earned 2000 total points
ID: 41868370
Try.. Do you know the format in terms of mm/dd/yyyy  or dd/mm/yyyy or mmmm d yyyy?

CultureInfo ci = new CultureInfo("en-GB");
rvCompDateCheck.MaximumValue = DateTime.Today.ToString("d", ci)

OR

rvCompDateCheck.MinimumValue = DateTime.Today.AddDays(-7).ToString("dd/mm/yyyy")
rvCompDateCheck.MaximumValue = DateTime.Today.ToString("dd/mm/yyyy")


OR

rvCompDateCheck.MinimumValue = DateTime.Today.AddDays(-7).ToString("mmmm d yyyy")
rvCompDateCheck.MaximumValue = DateTime.Today.ToString("mmmm d yyyy")
0
 
LVL 29

Expert Comment

by:Pawan Kumar
ID: 41871594
Hi edjones1,

Any update on this?

Regards,
Pawan
0
 

Author Closing Comment

by:Ed
ID: 41871906
That worked, thanks
0

Featured Post

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question