Reputation: 255
I have a application in which users need to fill out a timesheet for the amount of work that they have completed against a client. I currently use Timespan which works well up to a certain point.
The issue that I am currently having is that if a user has to put 4 hours or more a day against a customer it fails. The current message i am getting is SqlDbType.Time overflow. Value '1.04:00:00' is out of range. Must be between 00:00:00.0000000 and 23:59:59.9999999.
This will only be for my total which adds up all the days.
What I have is this
Model:
public TimeSpan Total
{
get
{
TimeSpan result = new TimeSpan(Monday.Ticks
+ Tuesday.Ticks
+ Wednesday.Ticks
+ Thursday.Ticks
+ Friday.Ticks
+ Saturday.Ticks
+ Sunday.Ticks);
return (result);
}
set
{
TimeSpan result = new TimeSpan(Monday.Ticks
+ Tuesday.Ticks
+ Wednesday.Ticks
+ Thursday.Ticks
+ Friday.Ticks
+ Saturday.Ticks
+ Sunday.Ticks);
}
}
I have tried removing .ticks
to .Hours
which partially works but gives me an excessive amount of 0s
http://prntscr.com/anaigx
Please can someone advise.
Upvotes: 2
Views: 173
Reputation: 4556
The problem you have having is due to your definition of SqlDbType.Time.
This type can only be used for a "normal" time, like 15:36, or whatever, it cannot store number of hours.
If you want to store amount of hours you should either use float type to store hours or int (or bigint) to store ticks.
Upvotes: 3