1

我有一个停车系统,我尝试制作一个 php 脚本来计算价格,而不是打印到 POS 打印机。

我从 mssql 得到了插入的时间,例如:2013-01-04 12:49:49

我想计算经过时间timenow();

比在几分钟内设置的值:

if 30 = 0;
if 60 = 1;
if 120 = 2,50

......和和:-)

是否可以?

4

1 回答 1

0

请尝试使用DATEDIFF

   SELECT CASE `X.ElapsedTime` 
               WHEN  MOD 30 = 0 THEN 0
               WHEN MOD 60 = 0 THEN 1 
               WHEN MOD 120 = 0 THEN 2 
               ELSE Null END AS `ElapsedCount` 
   FROM (SELECT  DATEDIFF(mi, startime, GetDate()) AS `ElapsedTime`
   FROM yourtable) X;

另一种方法是(如果你需要,你可以四舍五入):

   SELECT (`X.ElapsedTime`/60 + '.' + `X.ElapsedTime` MOD 60) as `ElapsedCount`
   FROM (SELECT  DATEDIFF(mi, startime, GetDate()) AS `ElapsedTime`
   FROM yourtable) X;

或使用hh

   SELECT  DATEDIFF(hh, startime, GetDate()) AS `ElapsedCount`
   FROM yourtable;

在评论中编辑 OP 的查询以使用 JOIN

SELECT top 1 dbo.Partners.IdPartner AS pid, 
dbo.Partners.PartnerName AS name, dbo.Partners.MemberNumber AS nr, 
dbo.T_PAID_KARTE.MAGNETNA_COD, dbo.T_PAID_KARTE.ACTIVE AS active, 
dbo.T_PAID_KARTE.TYP AS cardnime, dbo.T_PAID_KARTE.ID_PAIDBY, 
dbo.T_LOGG.EXIT AS exittime, DATEDIFF(mi, exittime, GetDate()) AS ElapsedCount, 
dbo.T_LOGG.ID_PARTNER 
FROM dbo.Partners
INNER JOIN dbo.T_PAID_KARTE
ON 
INNER JOIN dbo.T_LOGG
ON 
;
于 2013-02-04T17:07:23.297 回答