简体   繁体   English

以15分钟的间隔获取从给定的特定日期到“现在”的数据

[英]Get the data from the given specific date to 'now' by the interval of 15 minutes

Hi I am developing an application to retrieve data from one database server to another in C# Visual Studio 2010. 嗨,我正在开发一个应用程序,以在C#Visual Studio 2010中将数据从一个数据库服务器检索到另一个数据库服务器。

There is a requirement that data should be retrieve from the database by software installation date means a specific date to now means current time. 要求通过软件安装日期(从现在开始到现在的特定日期)到数据库的安装日期来检索数据。

There is also one more condition that when we get the oldest record like 2010-03-05 16:30:23 , the next record and the first record difference should be 15 minutes like next record should be 2010-03-05 16:45:23 . 还有一个条件是,当我们获得最早的记录(如2010-03-05 16:30:23 ,下一条记录和第一个记录的差应为15分钟,就像下一条记录应为2010-03-05 16:45:23 Database having records per minute. 每分钟有记录的数据库。

I have been tried the below but it's not fulfilling the requirement. 我已经在下面尝试过,但没有满足要求。

try
 {
   var con = new SqlConnection(Properties.Settings.Default.sConstr);
   var cmd = new SqlCommand("SELECT * from RAW_S001T01 where Date_Time >='" + time + "'", con);
   con.Open();
   var dr = cmd.ExecuteReader();
   var count = 0;
   while (dr.Read())
   {
    var Date = (dr["Date_Time"].ToString());
    var temp = Date.ToString(CultureInfo.InvariantCulture);
    var UTime=time.Split(':');
    string tempa = UTime[1].Substring(0, 2);
    time = temp +int.Parse("15");
    MessageBox.Show(time);
   }
 }
 catch (Exception ex)
 {
  MessageBox.Show(@"Error.",ex.ToString());
 }

How can we resolve this? 我们该如何解决呢?

Try this out: 试试看:
just modify your while loop and use this code. 只需修改您的while循环并使用此代码即可。

var Date = Convert.ToDateTime(dr["Date_Time"]);
Date = Date.AddMinutes(15);
MessageBox.Show(Date.ToString());

Hope this helps! 希望这可以帮助!

Just set the 15 minutes later time in a variable (as per Abhishek's answer). 只需将15分钟后的时间设置为一个变量即可(根据Abhishek的回答)。

Then process all items less than that time. 然后处理所有少于该时间的项目。 When you find an item with a time greater than that time, update that time (add another 15 minutes) and redirect the output to the next section of your data structure. 当您找到时间大于该时间的项目时,请更新该时间(再增加15分钟),然后将输出重定向到数据结构的下一部分。 Keep looping until you finish. 继续循环直到完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM