C
C#13mo ago
Mekasu0124

✅ Reading Time Stamps From Database and Summing Time c#

so I'm reading time stamps from a database, and I need to sum the total time
// database file
public List<ShiftModel> GetShiftEntries()
{
using SQLiteConnection conn = new(_dbFilePath);
using SQLiteCommand cmd = conn.CreateCommand();
SQLiteDataReader reader;

cmd.CommandText = @"SELECT * FROM records";
reader = cmd.ExecuteReader();

List<ShiftModel> shiftEntries = new();

while (reader.Read())
{
shiftEntries.Add(new ShiftModel()
{
StartTime = reader["StartTime"].ToString(),
EndTime = reader["EndTime"].ToString(),
StartMileage = Convert.ToInt32(reader["StartMileage"].ToString()),
EndMileage = Convert.ToInt32(reader["EndMileage"].ToString())
});
}

return shiftEntries;
}

public TotalModel GetTotals()
{
List<ShiftModel> shifts = GetShiftEntries();

Helpers hp = new();
hp.SumTime(shifts);
}

// helpers file
internal TimeSpan SumTime(List<ShiftModel> list)
{
}
// database file
public List<ShiftModel> GetShiftEntries()
{
using SQLiteConnection conn = new(_dbFilePath);
using SQLiteCommand cmd = conn.CreateCommand();
SQLiteDataReader reader;

cmd.CommandText = @"SELECT * FROM records";
reader = cmd.ExecuteReader();

List<ShiftModel> shiftEntries = new();

while (reader.Read())
{
shiftEntries.Add(new ShiftModel()
{
StartTime = reader["StartTime"].ToString(),
EndTime = reader["EndTime"].ToString(),
StartMileage = Convert.ToInt32(reader["StartMileage"].ToString()),
EndMileage = Convert.ToInt32(reader["EndMileage"].ToString())
});
}

return shiftEntries;
}

public TotalModel GetTotals()
{
List<ShiftModel> shifts = GetShiftEntries();

Helpers hp = new();
hp.SumTime(shifts);
}

// helpers file
internal TimeSpan SumTime(List<ShiftModel> list)
{
}
I need help creating a function in my helpers file that can read the StartTime and EndTime from the database which are strings of time like hh:mm:ss and sum them up into a total time span for display. Thanks
1 Reply
Mekasu0124
Mekasu0124OP13mo ago
nevermind. I can't display any results until I get the functionality of saving the information first. I'll be back
Want results from more Discord servers?
Add your server