Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: BIGINT to DateTime Post Reply Post New Topic
Author Message
Nissim
Newbie
Newbie


Joined: 04 May 2010
Online Status: Offline
Posts: 18
Quote Nissim Replybullet Topic: BIGINT to DateTime
    Posted: 15 Jun 2010 at 11:37pm
Hello experts,
I have this function in MS SQL that converts BIGINT to datetime. The problem is that my customer not allows using DB functions as a security policy in the organization.
The solution is to make the conversion in Crystal formula, but I don't know how to translate this MS SQL function to Crystal Formula. Please help.
The function is:
ALTER FUNCTION [dbo].[udfTicksToDateTime]
(
      @Ticks BIGINT
)
RETURNS DATETIME
AS
BEGIN
      DECLARE @Days BIGINT
      DECLARE @DaysBefore1753 BIGINT
      DECLARE @TimeTicks BIGINT
      DECLARE @Seconds BIGINT

      SET @Days = @Ticks / CONVERT(BIGINT,864000000000)
      SET @DaysBefore1753 = CONVERT(BIGINT,639905)
      SET @TimeTicks = @Ticks % CONVERT(BIGINT,864000000000)
      SET @Seconds = @TimeTicks / CONVERT(BIGINT,10000000)

      RETURN DATEADD(s,@Seconds,DATEADD(d,@Days - @DaysBefore1753,CONVERT(DATETIME,'1/1/1753')))
END
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 16 Jun 2010 at 4:16am

local numbervar iDays := {table.ticks} / 864000000000;
local numbervar iDaysBefore1753 = 639905
local numbervar iTimeTicks = {table.ticks} mod 864000000000
local numbervar iSeconds = iTimeTicks / 10000000

DATEADD(s,iSeconds,DATEADD(d,iDays - iDaysBefore1753,CDATE('1/1/1753')))

this is my stab at it.
 
Hope I'm close
IP IP Logged
Nissim
Newbie
Newbie


Joined: 04 May 2010
Online Status: Offline
Posts: 18
Quote Nissim Replybullet Posted: 16 Jun 2010 at 5:21am
Thanks a lot! It's almost 100%.
To be more precise, the divide sign should be backslash (\) otherwise it won't work.
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.000 seconds.