Solved

Asp/Net Validation date Issue

Posted on 2016-11-01
9
70 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:edjones1
  • 5
  • 4
9 Comments
 

Author Comment

by:edjones1
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 28

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 28

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:edjones1
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 28

Expert Comment

by:Pawan Kumar
ID: 41868341
Hi edjones1,

Glad that it helped !!

Regards,
Pawan
0
 

Author Comment

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

Accepted Solution

by:
Pawan Kumar earned 500 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 28

Expert Comment

by:Pawan Kumar
ID: 41871594
Hi edjones1,

Any update on this?

Regards,
Pawan
0
 

Author Closing Comment

by:edjones1
ID: 41871906
That worked, thanks
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
This video teaches users how to migrate an existing Wordpress website to a new domain.

839 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