The case I have here is I need to keep business hours in my sql database. Apparently I only need hh:mm. The way that I did was:
1. create 2 datetime fields in sql table to stroe the from and to.
2. in the maintenance form, create text fields to capture only hh:mm from user.
First of all, is it a right way to do? I mean, is it appropriate to use datetime field to store or I should use a string field to do so? Please note that the data are not used for display only.
I entered the hours thru Server Explorer in vs2003 prior to the maintenance form was created. It did allow me to enter only hh:mm to the cells. But when I examined the data in those fields during debugging, I found actually there is a date prior to the time.
My question is when I use vb code to update those fields, what should I put in the date portion. I don't think I can simply code like "table.FromField=txtFrom.text" and do a sql update.
Can someone advice me what is the proper way to get this done? Thanks a million.You can certianly do it the way you've done it thus far. However, date/time fields in sql have all kinds of additional features on them to calculate the date and time.
If you're simply looking for time in a specific format I would setup a char(5) or a VarChar(5) field and put the string in there. Then use a regular expression to validate it at the user interface.
But, like I previously said, you can certianly do it the way you did without issues.
Hope this help,
But then my issue is how to update the sql table in the future. As I said, I entered the dates thru vs2003 in the first set up. Down the road, if the user needs to change, I think the web form will crash out because trying to populate a datetime field without data in date portion. Would you agree with me?
Are you saying that you auto generated a form off of an sql table?
Sorry I confused you. I mean I created the table first and because there is just only one record in it so I simply entered data thru vs2003.
Now I am creating a form for my user to maintain info in that table. So if the user brings up the form, the text field will show 10:45 in that text fields.
Apparently when the user click save button, I'd have update the table with what is on the form. Then how am I going to update the datetime field with just a time. I have though about to concatenate it with a dummy date but it sounds very stupid and unprofessional.
Use the full date time functionality in SQL -
and format the output (displayed) to what you need...
thats the real way to accomplish the task...
good luck
take care
tony
Thanks Tony. I'm going to do research to see what the function you mentioned really does 'cause I'm at not well-versed in SQL. But I got a feeling that you meant to populate the entire date and time to the table, if this is true then what date I should put it in? Is my case very rare?
I couldn't find any date time functionalities to handle this situation except I found a page in MSDN about using data and time. It said ...
There are no separate time and date data types for storing only times or only dates. If only a time is specified when setting a datetime or smalldatetime value, the date defaults to January 1, 1900. If only a date is specified, the time defaults to 12:00 A.M. (Midnight).
In the mean time, I can only concatenate 1/1/1990 with user's input while updating the database. Does anybody have a better idea? Thanks.
0 comments:
Post a Comment