我有两个日期存储在mysql数据库中(Type = date).例如 -
日期1 = 2010-09-20
日期2 = 2010-10-20
我想计算这两个日期之间的天数.所以试过这个 -
$number_days = (strtotime($date2) - strtotime($date1) / (60 * 60 * 24));
Run Code Online (Sandbox Code Playgroud)
但这回归49
怎么会这样?
-------------------------------------更新------------ ------------------------------
好的,我意识到我的问题导致了一些混乱.我正在使用另一个函数来检索日期1,由于各种原因,这个日期没有正确返回,因此给出的天数实际上是正确的.当我从数据库中检索到正确的日期时,我上面的计算工作,考虑到/的优先级 -
谢谢你的回复.
我无法让这个程序计算空间,我觉得循环中存在逻辑错误,但我太缺乏经验而无法自己解决.有小费吗?
System.out.print("Enter a string: ");
String myString = keyboard.next();
int numBlanks = 0;
//find string length
int length = myString.length() - 1;
System.out.println("length " + length);
for(int sequence = 0; sequence >= length; ++sequence);
{
if(myString.charAt(length)==' ')
{
numBlanks += 1;
length -= length;
}
else
length -= length;
}
Run Code Online (Sandbox Code Playgroud) $teams = array(1, 2, 3, 4, 5, 6, 7, 8);
$game1 = array(2, 4, 6, 8);
$game2 = array();
Run Code Online (Sandbox Code Playgroud)
如果teams[x]不在game1那么插入game2
for($i = 0; $i < count($teams); $i++){
for($j = 0; $j < count($game1); $j++){
if($teams[$i] == $game1[$j]){
break;
} else {
array_push($game2, $teams[$i]);
}
}
}
for ($i = 0; $i < count($game2); $i++) {
echo $game2[$i];
echo ", ";
}
Run Code Online (Sandbox Code Playgroud)
我期待结果是:
1, 3, 5, 7,
Run Code Online (Sandbox Code Playgroud)
但是,我得到:
1, 1, 1, 1, 3, 3, 3, 3, …Run Code Online (Sandbox Code Playgroud) 以下代码有什么问题?怎么没有找到使用我的二进制搜索实现的信?
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
#include <cwctype>
using namespace std;
bool contains(string s, char a){
int m = 0;
int n = s.length()-1;
while (m != n) {
int k = (m + n) / 2;
if (s[k] == a)
return true;
if (s[k] < a) {
n = k - 1;
} else {
m=k + 1;
}
}
return false;
}
int main() {
string s = "miyvarxarmaiko";
char a = 'm';
if (contains(s,a) …Run Code Online (Sandbox Code Playgroud) 假设我使用2 AND和1 OR来检索结果,首先使用输入文本值进行测试name,我可以得到正确的结果但是当我更改$getc为除空字符串以外的任何值时,结果不会更改,它只查询name值.怎么了?
$query1 = "SELECT * FROM $tableName WHERE name LIKE '%$asd%' OR descriptions LIKE
'%$asd%' AND category='$getc' AND company_type='$dsp' LIMIT $start, $limit";
Run Code Online (Sandbox Code Playgroud) 我再次忘记了如何$_在二维数组的循环中表示数组.
foreach(@TWO_DIM_ARRAY){
my @ARRAY = $_;
}
Run Code Online (Sandbox Code Playgroud)
这是意图,但这不起作用.这样做的正确方法是什么?
#include <stdio.h>
typedef struct pduct {char name[20];
int price;
int stock;} PRODUCT;
void init(PRODUCT * product)
{
printf("What is the name of the product: ");
fgets(product->name, 20, stdin);
printf("DEBUG: Did it get written...: %s", product->name);
printf("What is the current stock of the item: ");
scanf("%d", product->stock);
printf("What is the price of the new item: ");
scanf("%d", product->price);
}
int main()
{
PRODUCT products[5];
init(products);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
现在,我真的有点亏.在运行它时,它会询问产品的名称,将其打印出来,以便我知道它存储了它,然后询问库存量,它将崩溃并返回-1.
我不知道出了什么问题.我试着换出fgets用scanf,只是可以肯定的,但同样的事情发生.我猜我struct的设置错了,但我不知道怎么回事.它char可能是阵列吗?此外,无论我如何安排它,它始终是第二个输入.那么为什么第一个这么好呢?
谢谢你的帮助!
%.8Ffprintf 中的格式说明符有什么作用?
什么F意思?
如果我有一个Java类,如下所示,相同的Perl表示是什么?
class Temp {
int my_int;
int my_array[];
Temp() {
}
};
Run Code Online (Sandbox Code Playgroud)
具体来说,我有兴趣知道如何使用数组作为对象变量?
我尝试了一些事情,但我收到了错误
typedef '\0' DEFAULT_VALUE;
Run Code Online (Sandbox Code Playgroud)
错误:'\ 0'之前预期的未命名id
typedef NULL DEFAULT_VALUE;
Run Code Online (Sandbox Code Playgroud)
错误:__null之前预期的未命名id
我在这做错了什么?