trx
trx

Reputation: 2157

Where clause in the Select statement with substring function

I have a table in the Azure SQL Database like below

enter image description here

I need to what day is today and compare against the OrderDay field. I was thinking I could do something like below in the where clause

   SUBSTRING(DATENAME(weekday,GETDATE()), 0, 4) 

There are is an issue with it when I added this in the select

enter image description here

Though I am running it today where I am still in the CST timezone its still Monday here and the Azure DB is located in EAST US but it is returning Tue.

Upvotes: 0

Views: 104

Answers (1)

NiharikaMoola
NiharikaMoola

Reputation: 5074

Azure SQL Database always follows UTC time zone.

Use AT TIME ZONE to convert it to CST or another non-UTC time zone.

Use the below syntax to get the day information in the CST time zone using AT TIME ZONE

SUBSTRING(DATENAME(weekday,getdate() AT TIME ZONE 'UTC' AT TIME ZONE 'Central Standard Time'), 0, 4)

enter image description here

You can also refer sys.time_zone_info view to check current utc offset information.

select * from sys.time_zone_info

enter image description here

Upvotes: 1

Related Questions