Problems sorting by date
- by Nathan
I'm attempting to only display data added to my database 24 hours ago or less. However, for some reason, the code I've written isn't working, and both entries in my database, one from 1 hour ago, one from 2 days ago, show up. Is there something wrong with my equation? Thanks!
public void UpdateValues()
{
double TotalCost = 0;
double TotalEarned = 0;
double TotalProfit = 0;
double TotalHST = 0;
for (int i = 0; i <= Program.TransactionList.Count - 1; i++)
{
DateTime Today = DateTime.Now;
DateTime Jan2013 = DateTime.Parse("01-01-2013"); //Hours since Jan12013
int TodayHoursSince2013 = Convert.ToInt32(Math.Round(Today.Subtract(Jan2013).TotalHours)); //7
int ItemHoursSince2013 = Program.TransactionList[i].HoursSince2013; //Equals 7176, and 7130
if (ItemHoursSince2013 - TodayHoursSince2013 <= 24)
{
TotalCost += Program.TransactionList[i].TotalCost;
TotalEarned += Program.TransactionList[i].TotalEarned;
TotalProfit += Program.TransactionList[i].TotalEarned - Program.TransactionList[i].TotalCost;
TotalHST += Program.TransactionList[i].TotalHST;
}
}
label6.Text = "$" + String.Format("{0:0.00}", TotalCost);
label7.Text = "$" + String.Format("{0:0.00}", TotalEarned);
label8.Text = "$" + String.Format("{0:0.00}", TotalProfit);
label10.Text = "$" + String.Format("{0:0.00}", TotalHST);
}