如何从sqlite日期和时间字符串中获取星期几?

时间:2022-06-01 21:28:14

I am using sqlite datetime commands to get, set and manipulate my date and time strings. I first construct the sql command in a const char* and then execute the command using sqlite3_exec while using a call back function to fetch the results if any from the (select from) commands.

我正在使用sqlite datetime命令来获取,设置和操作我的日期和时间字符串。我首先在const char *中构造sql命令,然后使用sqlite3_exec执行命令,同时使用回调函数从(select from)命令中获取结果。

orderDataBaseRc = sqlite3_exec(orderDataBase, pSQL[i], callback, 0, &zErrMsg);

Now I want to know the day of week (mo-su) and month (jan-dec) from my date and time string.

现在我想从我的日期和时间字符串中知道星期几(mo-su)和月份(jan-dec)。

How do I do that in sqlite? The documentation says something like i can get much wiser from the documentation and examples are hard to find.

我如何在sqlite中做到这一点?文档说明了我可以从文档中获得更多信息并且很难找到示例。

Let me give some examples of the sql commands that I am using:

让我举一些我正在使用的sql命令的例子:

"create table orderTable (OrderId integer primary key asc, CustomerId integer, OrderValue, OrderDescription, OrderDateTime DATE, OrderDueDateTime DATE)"

"create trigger insert_orderTable_OrderDate after insert on orderTable begin update orderTable set OrderDateTime = datetime('now') where rowid = new.rowid; end;"

"update orderTable set OrderDueDateTime = datetime('" << iOrderDateTime << "', '+1 day') where OrderId = " << orderId

So now I need to be able to know the day of the week and month of my date time string.

所以现在我需要能够知道我的日期时间字符串的星期几和月份。

According to the suggestion below I have constructed the following statement and fired off with sqlite3_exec:

根据下面的建议,我构建了以下语句并使用sqlite3_exec启动:

"select strftime('%A', OrderDateTime) FROM orderTable where OrderId = " << orderId;

Then in my callback function the following code (azColName[i] seems to come back with a copy of the sql statement:

然后在我的回调函数中,以下代码(azColName [i]似乎带有sql语句的副本:

char* columnName;

for(int i=0; i<argc; i++)
{
  columnName = azColName[i];
  string dayOfWeek;

  if(strcmp(columnName, "strftime('%A', OrderDateTime)")==0)
  {
    dayOfWeek = string(argv[i]);
  }
  ...
}

But it crashes on

但它崩溃了

dayOfWeek = string(argv[i]);

1 个解决方案

#1


0  

Use strftime() with %w and %m.

使用%f和%m的strftime()。

#1


0  

Use strftime() with %w and %m.

使用%f和%m的strftime()。