Click here to Skip to main content
15,891,762 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created drop down list that has populated 30 minutes interval from 8:00 am 9:00 pm. It is something like this 8:00am, 8:30 am, 9:00 am, 9:30 am, ......, 12:30 pm, etc. When user select any of this hh:mm from drop down list and save it in MS Sql as hh:mm. I created a table and it has a column called SendTime. Datatype is set up as Time(7). Is it correct way to do. Now, my question is how to define this data as hours and minutes in c# code so that I can save them in sql. Any help is appreciated.
Same thing also applies to Calendar. I have a calendar. I know how to get only date format (dd/mm/yyyy), but I do not know how to get only date (dd/mm/yyyy) is saved in MS sql.

Please help. Thank
Posted
Comments
ZurdoDev 4-Aug-14 12:28pm    
I don't agree with saving the the data in SQl as a string.

Where exactly are you stuck?
Member 10858162 4-Aug-14 12:43pm    
I am not sure how to save hh:mm in sql. What is the best practice to save in SQL. What I have on Web Form is that I have a calendar to choose date and dropdownlist for hour and minutes in format of hh:mm.I am confused with how to save date(dd/mm/yyyy) and time(hours and minutes) separately in differnt columns in SQL from user input from Web Form. Thank

1 solution

In SQL take the datatype as nvarchar n save it.

In C# take it as string only bcoz, on dropdown select u will get the time as 8:30am,
which includes numeric,double colon & 'am' also.

its better way to save it as nvarchar in sql n string in c#.

i use the same for Hijri dates. Hope u know the hirji date.

Best of luck.
 
Share this answer
 
Comments
Member 10858162 4-Aug-14 12:28pm    
Thank. No idea about hirji date. Need to do some research. If I used nvarchar in Sql, how can I do to fetch them as hh:mm to do business logic and calucation based on hh:mm?
ZurdoDev 4-Aug-14 12:28pm    
I think it is a bad idea generally speaking to store date and or time in SQL as just string.
abdul subhan mohammed 5-Aug-14 4:24am    
then take 2 columns in ur sql table one for hr n one for minutes,
n its datatype should be numeric for both the columns.
n
in c#: take is as int for both, try it n let me know.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900