كيف أحوّل حقل الوقت من رقم مخزّن في قاعدة البيانات إلى صيغة الوقت (HH:mm)؟

Viewed 0

برجاء إيضاح كيفية تحويل حقل الوقت من أرقام إلى وقت بقاعدة البيانات.

مثل:

  • 21600000 إلى 06:00
  • 22800000 إلى 06:20

شكراً.


Originally posted at https://answers.namasoft.com/question/470/ on 2018-12-04.

1 Answers

إذا كنت تحتاج هذا في تقرير، فأمامك حلّان:

  1. استخدم NamaRep.timeToString($F{fromTime}) وسيعطيك النص المطلوب مباشرة.
  2. أو استخدم NamaRep.timeToDecimal($F{fromTime}) لتحويل الوقت إلى رقم عشري.

وإذا كان ذلك داخل القوالب (templates) فيمكنك استخدام {timetostring(fromTime)} — مع ملاحظة أن هذا الجزء متوفّر في الإصدارات بعد 2018-12-05.

أما إذا أردت التحويل مباشرة في قاعدة البيانات، فيمكن استخدام هذه المعادلة:

select tl.fromDate, tl.fromTime,
       right('00'+cast(cast(((tl.fromTime+0.0)/3600000) as int) as varchar(2)),2)
       + ':' +
       right('00'+cast(cast(Round((((tl.fromTime+0.0)/3600000)-cast((tl.fromTime+0.0)/3600000 as int))*60,0) as int) as varchar(2)),2) fTime
from TimeAttendanceLine tl

وقامت بالنتيجة الموضحة في الصورة:

وصف الصورة

واستعلام كامل لحساب الفرق (المدة) أيضاً:

select tl.fromDate,
       right('00'+cast(cast(((tl.fromTime+0.0)/3600000) as int) as varchar(2)),2)
       + ':' +
       right('00'+cast(cast(Round((((tl.fromTime+0.0)/3600000)-cast((tl.fromTime+0.0)/3600000 as int))*60,0) as int) as varchar(2)),2) fTime,
       tl.toDate,
       right('00'+cast(cast(((tl.toTime+0.0)/3600000) as int) as varchar(2)),2)
       + ':' +
       right('00'+cast(cast(Round((((tl.toTime+0.0)/3600000)-cast((tl.toTime+0.0)/3600000 as int))*60,0) as int) as varchar(2)),2) tTime,
       right('00'+cast(cast(((tl.toTime-tl.fromTime+0.0)/3600000) as int) as varchar(2)),2)
       + ':' +
       right('00'+cast(cast(Round((((tl.toTime-tl.fromTime+0.0)/3600000)-cast((tl.toTime-tl.fromTime+0.0)/3600000 as int))*60,0) as int) as varchar(2)),2) spentTime
from TimeAttendanceLine tl

Originally posted at https://answers.namasoft.com/question/470/ on 2018-12-05.