Link to home
Start Free TrialLog in
Avatar of Ed
EdFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Asp/Net Validation date Issue

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
Avatar of Ed
Ed
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

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

Try..

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

x = now.AddDays(-7)
rvCompDateCheck.MinimumValue = x.ToShortDateString()
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
Avatar of Ed

ASKER

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.
Hi edjones1,

Glad that it helped !!

Regards,
Pawan
Avatar of Ed

ASKER

any ideas on how to read it in uk format?
ASKER CERTIFIED SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi edjones1,

Any update on this?

Regards,
Pawan
Avatar of Ed

ASKER

That worked, thanks