Gareth
Gareth

Reputation: 523

Loop Listbox SQL Insert with DateTime (incremented every 15 minutes)

I'm trying to get all the items in my listbox, then perform a SQL insert, but on the datetime I want each listbox item to have a 15 minute delay.

Can anyone point me in the right direction?

foreach (var item in myListBox)
{
    insert listitem1 with current date
    insert listitem2 with current date + 15 mins
    insert listitem3 with current date + 30 mins
}

The app i'm creating needs a time release function, meaning the user can not do anything until the date has passed.

I need to know how to loop the current date and 15 minutes for each item in the list. I know how to do the SQL insert, but I don't know how to add 15 minutes to each row.

DB: 1 item1 09:00:000 2 item2 09:15:000 3 item3 09:30:000

Upvotes: 0

Views: 88

Answers (1)

Marc
Marc

Reputation: 3959

I think you need something like this:

DateTime somedate = DateTime.Today;

for (int i = 0; i < myListBox.Count; i++)
{
    var increasedDate = somedate.AddMinutes(i*15);
    // and then insert myListBox.Items[i] with increasedDate 
} 

Upvotes: 3

Related Questions