[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Asp/Net Validation date Issue

Posted on 2016-11-01
9
Medium Priority
?
115 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 32

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 32

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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

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 32

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 32

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 32

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

Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
The viewer will learn how to dynamically set the form action using jQuery.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

649 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