Valid date

Valid date

Old forum URL: forums.lhotka.net/forums/t/1675.aspx


yh_ink posted on Friday, November 03, 2006

How to check for vaild date in the class. how to use the brokenrules.using smartdate.

i have smart date in my class. how should i assign this from my webform.

_Class.date =  this.testbox.text;  how should i assign this.The way i did it here is wrong

 

Wal972 replied on Friday, November 03, 2006

Have a look at the project it should the use of smartdates and how to get at them. Also depending on the Country watch the formating. The date is expected as a string so if its back to front ie. British not US or visa vera it wont work. I generally get my dates returned in dd-MMM-yy format for safety.

The other thing to watch is how you set the property to accept dates, ie format of string.

Hope that helps

malloc1024 replied on Friday, November 03, 2006

Your assignment doesn’t work because you are setting a string value to a date value.  Is the date property a date type or a smartdate type?

 

If the date property is a smartdate:

_Class.date.text  =  this.textbox.text

or

_Class.date.date  =  (datetime)this.textbox.text

 

If the date property is a date:

_Class.date = (datetime)this.textbox.text

 

I am not exactly sure what you mean by valid date.  Do you mean in a valid date format?  If so, there are many ways you can deal with this. Make sure the user can only enter dates in the correct format.  You can use the datetimepicker control for this.  You could also separate dropdown boxes for the month, day and year or create your own control.  You could try casting the string to a date or using a regex, but I think these are poor choices in this situation.

Copyright (c) Marimer LLC