Hello,
J'ai une fonction qui convertit une date au format DD-MM-YYYY en timestamp.
Avec certaine date ( 31/12/2099 par exemple), sql me retourne l'erreur:
Voici la fonction posant probleme:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 Msg*242, Niveau*16, État*3, Ligne*1 The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.
est ce que l'un d'entre vous pourrait m'indiquer où ca ne va pas dans ma fonction svp. Qu'est ce qui provoque cette erreur?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 ALTER FUNCTION [dbo].[DATETOLONG] (@datedb DATETIME) returns numeric(38) AS BEGIN DECLARE @epoch DATETIME, @offsetSeconds numeric(38), @tmpOffsetSeconds numeric(38), @retVal numeric(38), @offsetTz int, @offsetTzSign nvarchar(1) SET @epoch = CONVERT( DATETIME, '01/01/1970',103) SELECT @offsetTz= DATEPART(TZoffset, SYSDATETIMEOFFSET()) ,@offsetTzSign = SUBSTRING(DATENAME(TZoffset, SYSDATETIMEOFFSET()),1,1) SELECT @offsetSeconds= DATEDIFF(s,@epoch, convert(datetime,@datedb,103)) SET @tmpOffsetSeconds = @offsetSeconds*1000 IF @offsetTzSign ='+' SET @retVal = @tmpOffsetSeconds - (@offsetTz*60*1000) else SET @retVal = @tmpOffsetSeconds + (@offsetTz*60*1000) RETURN @retVal END;
j'ai l'impression que la date du 31 est prise pour le mois par SQL d'où l'erreur mais je ne suis pas sûr,
merci d'avance pour votre aide,
Partager