Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
wmahmud
Starting Member
2 Posts |
Posted - 2010-05-03 : 13:14:27
|
| We currently have custom reports setup in Crystal to capture data from our ServiceDesk. Everytime the time changes (March or November) we have our Resolve Date Time showing as 5hours+ of what it is in ServiceDesk. Eg. Ticket resolved at 2PM - but when run with Crystal it will show as 7PM.Our Open Date Time seems to remain fine all the time.Does anyone know what the issue may be or how we can go about resolving this? This is causing big issues for our reporting and throws times away off.Here is our main crystal report SQL file with the date/time function. Maybe someone can quickly help?Thank you.------USE [mdb]SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO--Install GetDateFromEpoch Functionif(exists(Select * from sysobjects where name = 'GetDateFromEpoch'))BEGINdrop function dbo.GetDateFromEpoch;ENDgoCREATE FUNCTION [dbo].[GetDateFromEpoch] (@Seconds int,@ConvertToLocalTime bit)RETURNS datetimeASBEGIN DECLARE @datLocalDateTime datetimeif(@ConvertToLocalTime = 0)BEGINSET @datLocalDateTime = dateadd(s, @Seconds, '1/1/1970')ENDELSEBEGINDECLARE @datToCheck datetimeSET @datToCheck = dateadd(s, @Seconds, '1/1/1970')DECLARE @intYear integerDECLARE @strMar1 varchar(18)DECLARE @strNov1 varchar(18)DECLARE @DayOfTheWeek integerDECLARE @DateDifference integerDECLARE @datDSTStarts datetimeDECLARE @datDSTEnds datetimeDECLARE @intGMTOffset integer/* Calculate when DST begins for the year in question */SET @intYear = DATEPART(yyyy, @datToCheck);SET @strMar1 = CONVERT(varchar(18), @intYear) + '0301 02:00:00';SET @DayOfTheWeek = DATEPART(dw, @strMar1); /* Day March 1 falls on in that year */if(@DayOfTheWeek = 1)BEGINSET @DateDifference = 0 /* Sunday is 1st day of the month */ENDelseBEGINSET @DateDifference = 15 - @DayOfTheWeek; /* # of days between that day and the 2nd Sunday ("the second Sunday in March ", i.e. when DST begins)*/END SET @datDSTStarts = DATEADD(dd, @DateDifference, @strMar1);/* Calculate when DST is over for the year in question */SET @strNov1 = CONVERT(varchar(18), @intYear) + '1101 02:00:00';SET @DayOfTheWeek = DATEPART(dw, @strNov1); /* Day Nov 1 falls on in that year */if(@DayOfTheWeek = 1)BEGINSET @DateDifference = 0 /* Sunday is 1st day of the month */ENDelseBEGINSET @DateDifference = 8 - @DayOfTheWeek; /* # of days between that day and the 2nd Sunday ("the second Sunday in March ", i.e. when DST begins)*/END SET @datDSTEnds = DATEADD(dd, @DateDifference, @strNov1);/* Determine if the date in question is in DST or not */IF @datToCheck BETWEEN @datDSTStarts AND @datDSTEndsBEGINSET @intGMTOffset = -4 /* DST */ENDELSEBEGINSET @intGMTOffset = -5 /* No DST */ENDSET @datLocalDateTime = DATEADD(hh, @intGMTOffset, @datToCheck)ENDRETURN @datLocalDateTimeENDGO |
|
|
wmahmud
Starting Member
2 Posts |
Posted - 2010-05-03 : 13:53:12
|
| This is the report where the issue is happening - others seem to be calculating things fine. Looks like the issue is only between March-November.-----Install Crystal_USD_SSP-Production-Outtage-Detailsif(exists(Select * from sysobjects where name = 'Crystal_USD_SSP-Production-Outtage-Details'))BEGINdrop procedure [Crystal_USD_SSP-Production-Outtage-Details];ENDgoCREATE PROCEDURE [dbo].[Crystal_USD_SSP-Production-Outtage-Details]@StartDate datetime,@EndDate datetimeASBEGINSET NOCOUNT ON;SELECT call_req.ref_num as 'PersID', dbo.GetDateFromEpoch(call_req.open_date, 1) as 'OpenDate', dbo.GetDateFromEpoch(call_req.resolve_date, 0) as 'ResolveDate',datediff(n,dbo.GetDateFromEpoch(call_req.open_date, 1),dbo.GetDateFromEpoch(call_req.resolve_date, 0)) as 'DurationMin',ca_owned_resource.resource_name as 'ResourceName',call_req.description as 'Description',call_req.z_lessons_learned as 'Lessons_Learned'FROM mdb.dbo.call_req call_req INNER JOIN ca_owned_resource on call_req.affected_rc = ca_owned_resource.own_resource_uuidWHERE ((((call_req.resolve_date is not null) and (dbo.GetDateFromEpoch(call_req.resolve_date, 0) between @StartDate and @EndDate)) or (call_req.close_date is not null)) and(call_req.active_flag = 0) and(dbo.GetDateFromEpoch(call_req.open_date, 1) between @StartDate and @EndDate) and(call_req.z_prod_outage = 1) and( ca_owned_resource.resource_name in ('Profile - IBS','Profile - FMS','Profile - Mortgages','DAWT - Toronto','DAWT - Ottawa','IVR - Toronto','IVR - Ottawa','Internet - Transactional','Filogix','Filenet','EWMS','Quick Modules','MAPS/CAPS','ABM','Internet - Static website','Orange Grove','Call Recording','Network - Toronto','Network - Ottawa','Email','Internet','BCP','CTI')))ENDgo |
 |
|
|
|
|
|
|
|