Question:
Problem is how to store only time in database.Database is SQL server?
vishakha
2007-01-01 05:49:44 UTC
I'm using datetimepicker control for entering time. The control's
format is set to custom and customFormat is HH:mm:ss tt.
In database time is getting saved as wel as date also.
Three answers:
anonymous
2007-01-01 07:33:08 UTC
If what you mean is, you want only the last time entered by any user to be stored whenever anyone uses a datetimepicker, just run a single update query with no conditions:



UPDATE timetable SET timecolumn = valueofpicker
mrdenny
2007-01-04 18:07:53 UTC
SQL Servers stores dates and times in a date time column. You can view only the time portion by using the convert function with the convertion type of 108 like this.

SELECT CONVERT(VARCHAR(10), getdate(), 108)

This will display the servers current time.



You can also store the data in a text field if you would like, however this can place limitations on you in the future.



If you do store the times in a text field, and you later convert the data to a datetime data type the date of 1/1/1900 to the time. This can be tested with this command.

SELECT CONVERT(DATETIME, CONVERT(VARCHAR(10), getdate(), 108))
Ivanhoe Fats
2007-01-01 06:03:08 UTC
all SQL date/time datatypes save the date as well as the time - it actually gets saved as a number like 12345.75 where the integer is the number of days since a pre-defined date (i think 1/1/900) and the fraction is the fraction of 24 hours



why not extract the time and save it in a text column ?



if you really want to use a date/time datatype then set the date to 0


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...