I've got a question about saving into datetime fields in a SQL Server table. A form I have create has two fields both for dates as well as other form fields, but the user may or may not fill in all the form fields, so when they click the save link I have a query which saves all the form fields whether they are blank or not. Unfortunately this is causing the two date fields to be saved in the database as "01/01/1900" even thoough they are blank fields.
What is a good way to not save blank date fields as "01/01/1900"?
Thanks
Stephen
Two choises:
1). If user doesn't leave the field blank, you can set DateTime = System.DateTime.Now, so that you can get the current dattime;
2). Allow your datetime column in your table as NULL value, or GetDate() as Default value, so that if user didn't put value, you can set the field as NULL or current datetime
Hope it helps
No comments:
Post a Comment