如何更改db [php]中存储的日期格式?(How to change format of date from that stored in db [php]?)
我将日期时间存储在数据库中为
$date=date("Ymd H:i:s");
现在在大多数地方我使用的格式与存储的格式相同2016-03-01 19:04:18 ,但在一个地方我更喜欢输出为3月01日19:04如何更改输出格式从数据库2016-03-01 19:04:18到3月1日19:04 。I am storing date time in database as
$date=date("Y-m-d H:i:s");
Now on most places I use it in the same format as it is stored 2016-03-01 19:04:18, but on one place I would rather prefer output to be March 01 at 19:04 how can I change format of output from database from 2016-03-01 19:04:18 to March 01 at 19:04.
原文:https://stackoverflow.com/questions/35744559
最满意答案
您必须将isnull应用于列,而不是整个查询。
试试下面的内容
select ISNULL(LeaveApply_Id,0) AS ID from Tbl_Stud_Leave_Apply where Candidate_Id= @Candidate and (@date between Stud_LeaveFromDate and Stud_LeaveToDate)
在上面的
@Candidate
和@date
被动态传递给查询。You have to apply the isnull to the column, not to the whole query.
Try the below
select ISNULL(LeaveApply_Id,0) AS ID from Tbl_Stud_Leave_Apply where Candidate_Id= @Candidate and (@date between Stud_LeaveFromDate and Stud_LeaveToDate)
In the above
@Candidate
and@date
are dynamically passed to query.
相关问答
更多-
您必须将isnull应用于列,而不是整个查询。 试试下面的内容 select ISNULL(LeaveApply_Id,0) AS ID from Tbl_Stud_Leave_Apply where Candidate_Id= @Candidate and (@date between Stud_LeaveFromDate and Stud_LeaveToDate) 在上面的@Candidate和@date被动态传递给查询。 You have to apply the isnull to the co ...
-
与某些编程语言不同,您不能指望 T-SQL WHERE子句中的短路 。 它可能会发生,也可能不会发生 。 Unlike in some programming languages, you cannot count on short-circuiting in T-SQL WHERE clauses. It might happen, or it might not.
-
在HAVING和WHERE子句之间使用OR运算符进行SQL查询(Sql query with an OR operator between a HAVING and WHERE clause)[2022-02-24]
以下将起作用 - 您不必在HAVING子句中指定聚合 SELECT dept, SUM (salary) FROM employee GROUP BY dept HAVING dept = "HR" or SUM (salary) > 25000 但你的声明“支付超过25000的所有员工”并不清楚。 你要吗 所有员工每人收入超过25000的部门,或所有员工总共收入超过25000的部门? 上面的查询为您提供了第二个选项,因为它最接近您的原始查询 The below will work - you do ... -
如有疑问,请阅读文档 : <=>是一个NULL安全相等的。 此运算符执行与=运算符类似的相等比较,但如果两个操作数均为NULL,则返回1而不是NULL;如果一个操作数为NULL,则返回0而不是NULL。 When in doubt, read the documentation: <=> is a NULL-safe equal. This operator performs an equality comparison like the = operator, but returns 1 rather t ...
-
在你的“B”表中包裹一个OR ,比如: AND (len(searchString)=0 OR table_b.column_b LIKE "%searchString%" ) 这样,如果字符串没有值,则其长度将为零,并且OR的第一部分将被评估,总是返回为真,并将该部分的等式返回为有效,并使用LIKE子句忽略另一半。 您可以根据需要应用相同的链接表。 Wrap an OR around your "B" table, such as: AND (len(searchString)=0 OR table_b ...
-
“OR只评估表达式,直到找到TRUE结果为止” 它只需要,但这不是你的问题(实际上这是在原始情况下拯救你的东西)。 你的两个查询并不是真正等同的。 我认为你在Column2中有NULL ,它永远不会导致(Column2 LIKE ISNULL(@Param2, '') + '%')为真 - 在原始版本中, @Param2 = ''掩盖了这种情况,因为它是真的(有时) 也许: (ISNULL(Column2, '') LIKE ISNULL(@Param2, '') + '%') 记住NULL的三值逻辑: ...
-
IN运算符SQL(IN Operator SQL)[2022-03-17]
这是因为null = null始终为false用于null的运算符是IS或IS NOT您可以使用下面的查询来获得期望的输出 SELECT n FROM Nums WHERE n IN (1,2) OR n IS NULL [编辑] Thanx @Buckwad OK I have found the answer SELECT n FROM Nums WHERE n NOT IN (1, 2, null) evaluates to SELECT n FROM Nums n!=1 AND n! ... -
SQL中的<>运算符(<> operator in SQL)[2022-06-15]
select * from table where COALESCE(IsDeleted, 0) <> 1 -- or ISNULL instead of COALESCE. --ISNULL seems to be better in subqueries, but it's not ANSI SQL. 要么 select * from table where IsDeleted <> 1 or IsDeleted IS NULL select * from table where COAL ... -
做这个: WHERE Name LIKE '%' + @nameparam + '%'"; Do this: WHERE Name LIKE '%' + @nameparam + '%'";
-
使用IN运算符的SQL查询(SQL query with IN operator)[2023-10-18]
您的where子句限制Nation表中的项目,但不限制Customers表。 或者,以另一种方式查看,子查询选择正确的行,但之后您已向查询(Customers)添加了一个没有限制的新表。 解决这个问题的正确方法不是使用IN运算符,而是使用JOIN运算符。 使用customer表中的nation键将两个表连接在一起。 你没有给我们所有的列名,所以我将不得不猜测国家的关键。 SELECT c.C_ID, c.C_NAME, n.N_NAME FROM customers c INNER JOIN nation ...