Solved

Asp/Net Validation date Issue

Posted on 2016-11-01
9
37 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 17

Expert Comment

by:Pawan Kumar Khowal
ID: 41868160
Try..

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

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

Expert Comment

by:Pawan Kumar Khowal
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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 17

Expert Comment

by:Pawan Kumar Khowal
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 17

Accepted Solution

by:
Pawan Kumar Khowal 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 17

Expert Comment

by:Pawan Kumar Khowal
ID: 41871594
Hi edjones1,

Any update on this?

Regards,
Pawan
0
 

Author Closing Comment

by:edjones1
ID: 41871906
That worked, thanks
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now