系统间缓存中两个日期时间戳之间的差异

Difference between two date time stamp in Intersystems Cache

我想找出两个日期时间戳之间的小时数和分钟数。

如果例如

 sDateTime = 2016-01-01 01:00 
 eDateTime = 2016-01-03 02:30

我希望它输出为 49:30(49 小时 30 分钟) 我想不出解决这个问题的方法。

我目前拥有的:

    Set oMNOF=##class(MNOF.MNOF).%OpenId(Id)

Set zstartDt=oMNOF.sDateTime 
Set startDt=$PIECE(zstartDt,",",1)          
Set startTime=$PIECE(zstartDt,",",2)    

Set zendDt=oMNOF.eDateTime 
Set endDt=$PIECE(zendDt,",",1)          
Set endTime=$PIECE(zendDt,",",2) 

    set dateDiff=((endDt - startDt))     //2 days 
set timeDiff=(endTime - startTime)    //outputs 5400 seconds

     set d = (dateDiff * 24 * 60 * 60)
set h = ((timeDiff - d) / 60)
set m = timeDiff - (d) - (h * 60)

感谢您的帮助。

另一个选项:

USER>set mm=$system.SQL.DATEDIFF("mi","2016-01-02 01:00","2016-01-03 02:30")

USER>write "hours=", mm \ 60
hours=25
USER>write "minutes=", mm # 60
minutes=30

您好,感谢大家的帮助。 我设法想出了以下内容,如果有人可以对此进行改进,我将不胜感激。

<script language="cache" method="MGetData" arguments="pStartDt:%String,pEndDt:%String,pTimeField:%String" returntype="%Library.String">
set val1="00"

//HOUR: check if length equals 1
if $LENGTH($SYSTEM.SQL.FLOOR($system.SQL.DATEDIFF("ss",pStartDt,pEndDt)/3600))=1{
    //add leading zero
    set val1 ="0"_$SYSTEM.SQL.FLOOR($system.SQL.DATEDIFF("ss",pStartDt,pEndDt)/3600)

}
else{
    //get without leading zero
    set val1 = $SYSTEM.SQL.FLOOR($system.SQL.DATEDIFF("ss",pStartDt,pEndDt)/3600)
}

//MINUTES: check if length equals 1
if $LENGTH($SYSTEM.SQL.FLOOR($system.SQL.DATEDIFF("ss",pStartDt,pEndDt)/60) - ($SYSTEM.SQL.FLOOR($system.SQL.DATEDIFF("ss",pStartDt,pEndDt)/3600)*60))=1{

    //add leading zero
    set val2 ="0"_($SYSTEM.SQL.FLOOR($system.SQL.DATEDIFF("ss",pStartDt,pEndDt)/60) - ($SYSTEM.SQL.FLOOR($system.SQL.DATEDIFF("ss",pStartDt,pEndDt)/3600)*60))

}
else{

    //get without leading zero
    set val2 = ($SYSTEM.SQL.FLOOR($system.SQL.DATEDIFF("ss",pStartDt,pEndDt)/60) - ($SYSTEM.SQL.FLOOR($system.SQL.DATEDIFF("ss",pStartDt,pEndDt)/3600)*60))

}

//insert result data into the time field
Write "document.getElementById('"_pTimeField_"').value='"_val1_":"_val2_"';"

//Write "alert('"_val1_"^"_val2_"');"

QUIT 1