Dhanil Dinesan
Dhanil Dinesan

Reputation: 575

SQL Server returns different result for the same Date selection query, In different scenarios

I was trying to get a date based on Timezone and I was nearly successful with that. But I got an issue when I incorporate that query with the stored procedure. Here is the code which gives me the correct output.

    DECLARE 
@TimeZone VARCHAR(100) = 'India Standard Time'
declare @EndDate DATETIME = (SELECT (CONVERT( datetime,SYSDATETIMEOFFSET()  AT TIME ZONE @TimeZone)))   
select @EndDate

and the output is (correct o/p)

2019-12-23 20:43:18.020

Then I incorporate it with a stored procedure

which comes under an if condition

O/P is like this

Dec 23 2019  8:38PM

can anybody help me with this

Upvotes: 1

Views: 201

Answers (1)

PeterHe
PeterHe

Reputation: 2766

The value of the variable looks correct but just shown in different format. You can force it to show in the format you want:

select CONVERT(nvarchar(100),@EndDate,120) as EndDate;

Upvotes: 1

Related Questions