按经过时间php mssql server计算价格

时间:2013-02-04 17:02:36

标签: php sql-server-2008

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

我从mssql获得了如下的时间:2013-01-04 12:49:49

我想计算timenow();

的精确时间

比在几分钟内设定这样的值:

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

......和: - - )

有可能吗?

1 个答案:

答案 0 :(得分: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 
;