Click here to Skip to main content
15,921,226 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
TimeSpan entry=AdjustTime(int row, string colName);
private TimeSpan AdjustTime(int row, string colName)
{
    string s1 = dataGridView1.Rows[row].Cells[colName].Value.ToString();
    return ((!string.IsNullOrEmpty(s1)) ? TimeSpan.Parse(s1 = (s1 == "24:00:00") ? "23:59:59" : s1) : TimeSpan.Zero);
}

in this code returned timespan value is used to determines the entry time of a person and If "s1=""" so function will return Timespan.zero.the question is, in this state how I distinguish entry is default value or person entry time is "00:00"?
Posted

1 solution

You can't directly.
You need some other indicator.
You could try using a nullable TimeSpan:
C#
TimeSpan? entry=AdjustTime(int row, string colName);
private TimeSpan? AdjustTime(int row, string colName)
{
    string s1 = dataGridView1.Rows[row].Cells[colName].Value.ToString();
    return ((!string.IsNullOrEmpty(s1)) ? TimeSpan.Parse(s1 = (s1 == "24:00:00") ? "23:59:59" : s1) : null);
}

Or you could use another impossible value for the default:
C#
TimeSpan entry=AdjustTime(int row, string colName);
private TimeSpan AdjustTime(int row, string colName)
{
    string s1 = dataGridView1.Rows[row].Cells[colName].Value.ToString();
    return ((!string.IsNullOrEmpty(s1)) ? TimeSpan.Parse(s1 = (s1 == "24:00:00") ? "23:59:59" : s1) : TimeSpan.MinValue);
}
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 13-Mar-14 17:43pm    
It's a good point to use "some other indicator", and this is an appropriate indicator, my 5. Using special value to conduct the idea of uncertain or uninitialized time would be a serious flaw.
—SA
Matt T Heffron 13-Mar-14 18:04pm    
Thanks
mit62 14-Mar-14 23:03pm    
Thanks a lot

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