[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Asp/Net Validation date Issue

Posted on 2016-11-01
9
Medium Priority
?
135 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
  • 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 37

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 37

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 37

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 37

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 37

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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
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…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Suggested Courses
Course of the Month17 days, 16 hours left to enroll

830 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